简体   繁体   中英

How to skip the update query execution IN Hibernate after criteria select

I am getting one stange HQL printed in my console.I didnt use any update script in repository.I am creating session factory and hibernate session via Localsession factory builder of spring . I am getting one update query printed after my criteria select .

 Criteria criteria = session
                .createCriteria(Test.class);
        criteria.add(Restrictions.eq("testKey.fode",
                airlineCode));
        criteria.add(Restrictions.eq(
                "testKey.number",eId));
        criteria.createAlias("currentMonth", "requiredMonth");
        criteria.add(Restrictions.eq("requiredMonth.type",
                currentMonthType));
        statusList = criteria.list(); 

In the above criteria.list() working fine but after tat update query has been printed with most of columns in the table with ? symbol. Like below

update STATUS set CUR_BASE=?, CUR_TYPE=?, CUR_GRP=?, CUR_TOM=?, CHECK_MON=? where FODE=? and CURRENTMONTH=? and E_NUM=?.

I want to know is there any way to skip the update query execution.

My Persistence Config:

@Configuration
@EnableTransactionManagement
@PropertySource({ "classpath:persistence.properties" })
@ComponentScan({ "com.test.test2.*" })
public class PersistenceConfiguration1 {

    @Autowired
    private Environment env;

    @Bean(name="dsession")
    public LocalSessionFactoryBean sessionFactory() {
        LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
        sessionFactory.setDataSource(testDataSource());
        sessionFactory.setPackagesToScan(new String[] {
                " com.test.test2"});

        return sessionFactory;
    }

    @Bean
    public DataSource testDataSource() {
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName(env.getProperty("jdbc.driverClassName"));
        dataSource.setUrl(env.getProperty("jdbc.url"));
        dataSource.setUsername(env.getProperty("jdbc.user"));
        dataSource.setPassword(env.getProperty("jdbc.pass"));

        return dataSource;
    }

    @Bean(name="dTransaction")
    @Autowired
    public HibernateTransactionManager transactionManager(
            SessionFactory sessionFactory) {
        HibernateTransactionManager txManager = new HibernateTransactionManager();
        txManager.setSessionFactory(sessionFactory);

        return txManager;
    }
}

I found the issue in my code.Thanks @K139 for pointing me to analyze the path.

After Criteria.list() I am setting some value in the returned list from DB

   statusList = criteria.list();
  status = statusList.get(0);\
status.setFode(status.getFode.trim)

I moved the trim function from repository to other layer its working fine now. Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM