Greetings,
Currently developing small web service application where response from web service (using CXF + Spring) processed and saved to database. To work with database I am using Hibernate(3.5). Browsing some Hibernate + Spring example on web, I often can see the usage of HibernateTemplate so I am a bit confused about this moment and wanted to ask:
Do you use HibernateTemplate in your Hibernate3 applications?
When does HibernateTemplate can make your development life better and based on what points can I decide do I need to use it or not ?
Thanks.
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
HibernateTemplateno longer be used.Specifically, what
HibernateTemplatedid 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),
HibernateTemplatehas been removed. See Hibernate for the currently suggested usage patterns.