Can someone outline the steps required to get hibernate working with spring mvc.
I’ve seen EntityDao’s that basically inherit from a GenericDAo.
The generic Dao has basic operations like GetAll, GetByID, Save, Delete, etc.
And inside their methods they use:
getHibernateTemplate
So basically the Session has to be wired up in a bean, and mysql settings have to be set.
I find the spring documentation to be a little confusing: http://static.springsource.org/spring/docs/3.0.0.RELEASE/spring-framework-reference/html/orm.html#orm-hibernate
The basic components are:
SessionFactory. This is typically done by theLocalSessionFactoryBean, as used in the example in the link you posted. This exposes a Spring-managed bean that implements the HibernateSessionFactoryinterface.SessionFactory. In many cases, the simplest thing to do here is to extend the convenientHibernateDaoSupportclass, which has asessionFactoryproperty.HibernateDaoSupportproves agetHibernateTemplate()method, which gets a HibernateSessionfrom theSessionFactoryand wraps it in aHibernateTemplateobject, which provides various convenience methods for doing common Hibernate operations, and is generally more useful than the rawSessioninterface.Using this pattern, there is very little direct interaction between application code and the Hibernate API itself, its mostly done though s Spring intermediate layer. Some would call this a good thing, others would rather Spring stayed out of the way. This is a perfectly good alternative – there’s nothing to stop you injecting your bean with
SessionFactoryand using the Hibernate API directly. TheHibernateDaoSupportandHibernateTemplateclasses are there purely as a convenience.