-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Description
Manuel Dominguez Sarmiento opened SPR-11291 and commented
We are well aware that the recommended approach nowadays is NOT using HibernateTemplate. However, projects exist that need to be upgraded to newer library versions, and the change needs to be as smooth as possible.
Recently, we needed to upgrade a very large project (about 100 DAOs) to Hibernate 4, for several reasons (mainly fixes that were not available in the 3.6.x branch). The project used HibernateTemplate for all DAO access (which was the recommended approach back when the project was started in 2005/2006). We found out the hard way that Spring did not provide a HibernateTemplate in the hibernate4 subpackage.
Before anyone cries out "refactor your code to use sessionFactory.getCurrentSession()" let me remind you that HibernateTemplate offers several extra features:
- Automatical exception translation to the Spring hierarchy
- Obtaining a new session automatically when a transaction is not active
- Filter configuration
- Query cache region configuration
- fetch size tuning
- max. results
- HibernateOperations API (which IMO is cleaner than direct Hibernate Session usage, and uses generics whenever possible while Hibernate Session does not)
- etc.
All of this can be refactored to use Hibernate directly. However, such refactoring is a big risk for a large project, and a huge opportunity to introduce regression bugs all over the place in the data access layer.
I'm sure that I'm not alone in the sentiment that Spring should provide a smooth migration path from Hibernate 3 to Hibernate 4. Currently it does not. If HibernateTemplate were an obscure, seldom used class, I would not have a problem. But HibernateTemplate use is widespread, given that it was the recommended approach for such a long time (even if a long time has passed since then)
Affects: 3.2 GA, 4.0 GA
Attachments:
- HibernateAccessor.java (13.64 kB)
- HibernateCallback.java (2.58 kB)
- HibernateDaoSupport.java (5.90 kB)
- HibernateOperations.java (46.88 kB)
- HibernateTemplate.java (43.79 kB)
Issue Links:
- Doc: Spring 3.x and Hibernate 4 are not compatible. Unable to use HibernateTemplate. [SPR-9365] #14002 Doc: Spring 3.x and Hibernate 4 are not compatible. Unable to use HibernateTemplate.
- HibernateInterceptor variant for Hibernate 4 [SPR-9028] #13667 HibernateInterceptor variant for Hibernate 4
1 votes, 4 watchers