Spring hibernate template when to use and why?

All spring templates (hibernate, jdbc, rest, jpa etc.) have the same pros and cons:

Pro: They perform common setup routines for you, let you skip the boilerplate and concentrate on the logic you want.

Con: you are coupling your application tightly to the spring framework. For this reason, Spring recommends that HibernateTemplate no longer be used.

Specifically, what HibernateTemplate did for you was to automatically open and close sessions and commit or rollback transactions after your code executed. However, all of this can be achieved in an aspect-oriented way using Spring’s Declarative Transaction Management.

Reference:


Update:

As of Spring 3.1 (and newer versions), HibernateTemplate has been removed. See Hibernate for the currently suggested usage patterns.

Leave a Comment