Skip to content

Re-consider including HibernateTemplate and related classes for Hibernate 4 [SPR-11291] #15915

@spring-projects-issues

Description

@spring-projects-issues

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:

Issue Links:

1 votes, 4 watchers

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions