简体   繁体   中英

this.getHibernateTemplate().delete(bp) does not delete instantly

I have a method in which I do the following

// First delete the entry by 
this.getHibernateTemplate().delete(test);

// In Next Line try to load the latest values by 
List<test> = this.getHibernateTemplate().find("from test");

In this case, the deleted entry also gets loaded in List of test objects. I do not want the deleted entry to get loaded in List<test> = this.getHibernateTemplate().find("from test");

Hibernate doesn't execute your delete until you either commit or flush. You can call flush on the session after deleting and before the call to find.

Added the following code to make it work.

Transaction beginTransaction = this.getHibernateTemplate().getSessionFactory().getCurrentSession().beginTransaction();

// First delete the entry by 
this.getHibernateTemplate().delete(test);

beginTransaction.commit();

// In Next Line try to load the latest values by 
List<test> = this.getHibernateTemplate().find("from test");

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