I’m refreshing my Spring knowledge, reading the reference documentation for spring 3.1. Last time i read about spring as best practice was set JdbcDaoSupport and HibernateDaoSupport, now they are not even mentioned.
Also I have the impression that HibernateTemplete is not preferable any more, instead we just inject the SessionFactory in the DAO. So my question is: What are the best practices for using Spring with JDBC/Hibernate.
I’m refreshing my Spring knowledge, reading the reference documentation for spring 3.1. Last time
Share
HibernateDaoSupportandHibernateTempleteused to provide the facility for translation of Hibernate 2’s checked exceptions into Spring’s non-checked exception hierarchy. Also,HibernateTempleteprovided a richer API than the raw HibernateSessioninterface.The exception translation can now be done using the
@Repositoryannotation and transparent exception translation, possible because Hibernate 3 uses runtime exceptions. Also, theSessioninterface is richer than it used to be, although it still falls short of the number of convenience methods provided byHibernateTemplate.In short, these support classes aren’t as useful as they used to be, and now writing Spring DAOs without reference to the Spring API is easy. However, they still provide some additional convenience, so you may choose to still use them.
There is no right or wrong approach, though.