Why is HibernateDaoSupport not recommended?

Using HibernateDaoSupport/HibernateTemplate is not recommended since it unnecessarily
ties your code to Spring classes.

Using these classes was inevitable with older versions of Hibernate in order to integrate support of Spring-managed transactions.

However, since Hibernate 3.0.1 you don’t need it any more – you can write a code against a plain Hibernate API while using Spring-managed transactions. All you need is to configure Spring transaction support, inject SessionFactory and call getCurrentSession() on it when you need to work with session.

Another benefit of HibernateTemplate is exception translation. Without HibernateTemplate the same functionality can be achieved by using @Repository annotation, as shown in Gareth Davis’s answer.

See also:

Leave a Comment