What is the difference between getHibernateTemplate (). Flush () and getSession (). Flush ()

I am using Hibernate 3.2.6. And I came across an exception

keep a temporary copy before flushing

In my code, sometimes we use getSession().flush() , and sometimes we use getHibernateTemplate().flush() in one transaction.

Could you tell me what is the difference between the two?

+8
java spring hibernate
source share
1 answer

HibernateTemplate deprecated Spring code, starting from the days before Spring, has moved to annotations as the preferred transaction management method. This is not part of the hibernate itself. The template code abstracted from the mechanics of creating, committing, and rolling back transactions, allowing the developer to focus solely on their business logic. HibernateTemplate is now considered a redundant Spring community and has been completely removed in Spring support for Hibernate 4.

From the official documentation:

NOTE. Starting with Hibernate 3.0.1, the Hibernate transactional access code can also be encoded in the usual Hibernate style. Therefore, for recently launched projects, consider encoding data access objects based on SessionFactory.getCurrentSession () instead of the standard Hibernate3 type.

During the transition process, your code is most likely a confusion of legacy code and mixed approaches between developers.

+9
source share

All Articles