When commit happens in case of getHibernateTemplate ()

I use Spring Hibernate integration in my application, and DAO classes are extended by HibernateDaoSupport . Suppose I save some object using the code getHibernateTemplate().save(object) Using the sleep pattern, I donโ€™t need to explicitly commit the transaction. I want to know at what point the data is captured.

Consider the code snippet below

 public void saveObject(){ ....... getHibernateTemplate().save(object1); .... .... getHibernateTemplate().save(object2); } 

In the above code, exactly at what point object1 will be inserted into DB..after getHibernateTemplate().save(object1); or at the end of the method?

+4
source share
3 answers

It depends on the configuration settings of the transaction manager and / or purge mode. http://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/FlushMode.html

0
source

You should use this:

  @Override public void addAccount(Account account) { hibernateTemplate.getSessionFactory().getCurrentSession().beginTransaction(); hibernateTemplate.saveOrUpdate(account); hibernateTemplate.getSessionFactory().getCurrentSession().getTransaction().commit(); } 
0
source

No one.

In the default configuration, insert are executed at the last moment, they can, I mean, hibernate saves them until the end of the transaction or any other point (if there are flush commands, some other select commands ...).

But committing does not depend on it at all, committing only when you (or Spring!) Complete the transaction. So it depends on how you manage the transaction, if you are using Spring declarative transaction management, then it is important which method has the transaction attribute and which attribute it has.

0
source

All Articles