I\'m really new to Hibernate and have been mulling over something for a while now. I have two databases that I have JNDI connection strings defined to in Tomcat\'s context.xml.
The HibernateTemplate
constructor takes a SessionFactory
as argument. I don't know what getHibernateTemplate()
does in your code, but it should return a HibernateTemplate
built with one of the SessionFactory beans you defined (either by declaring them in the spring context xml file, or by constructing them in Java from one of the injected session factories).
Note that, as the documentation of HibernateTemplate says (in bold):
As of Hibernate 3.0.1, transactional Hibernate access code can also be coded in plain Hibernate style. Hence, for newly started projects, consider adopting the standard Hibernate3 style of coding data access objects instead, based on SessionFactory.getCurrentSession().
I would inject the session factory directly, and use the Hibernate API directly. HibernateTemplate doesn't bring much over the Hibernate API and often gets in the way, IMHO. (For example by not providing an equivalent to Query.uniqueResult()
).