Hi. My application using Spring and Hibernate as a persistenting technology. Here is the class that uses Hibernate :
In the application context, I created a datasource, a session factory, and an instance of StoringEvents successfully (no excpetions throws).
(It worth noting that I didn't create a transaction manager). But when trying to run the application (web one), I got a NullPointerException at getHibernateTemplate().save(le); The getHibernateTemplate( ) returns null. Any ideas ? Thanks.
Convenient super class for Hibernate data access objects.
Requires a SessionFactory to be set, providing a HibernateTemplate based on it to subclasses. Can alternatively be initialized directly via a HibernateTemplate, to reuse the latter's settings like SessionFactory, exception translator, flush mode, etc.
This base class is mainly intended for HibernateTemplate usage but can also be used when working with SessionFactoryUtils directly, e.g. in combination with HibernateInterceptor-managed Sessions. Convenience getSession and releaseSession methods are provided for that usage style.
This class will create its own HibernateTemplate if only a SessionFactory is passed in. The allowCreate flag on that HibernateTemplate will be true by default. A custom HibernateTemplate instance can be used through overriding createHibernateTemplate.
So the configuration you've used should work without having to manually inject a HibernateTemplate. This technique is standard and is demonstrated in the PetClinic sample app. All the DaoSupport classes work this way. Perhaps something else is missing that is causing the NPE. Maybe you should post the full stack trace.
BTW, DriverManagerDataSource is not a pooling DataSource and is meant primarily for testing. PetClinic shows alternative DataSource definitions that provide pooled Connections you can use in a production environment.
kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg
I would also suggest creating your own thread for questions instead of tacking onto an existing thread, if you feel that the problem is related it is probably helpful to include a link back to the original thread as well.
Well behaved women rarely make history - Eleanor Roosevelt. tiny ad: