Ok, I'm getting a strange error when I do this. HibernateTemplate is a POJO, and I want to inject it into my BaseDAO so that I can also use JdbcTemplate (through DI) instead of using single-inheritance for one (HibernateDaoSupport) and then an ugly hack to get a JDBC template.
here's my applicationContext:
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate.Hibernate Template">
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >
<property name="dataSource"><ref bean="promiseds"/></property>
</bean>
<bean id="baseDAO" class="sg.com.crownsys.promise.dao.implementation. BaseDAOImplementation">
<property name="hibernateTemplate"><ref bean="hibernateTemplate"/></property>
<property name="jdbcTemplate"><ref bean="jdbcTemplate"/></property>
</bean>
Now my other DAOs just inherit from baseDAO so they don't need any DI, but in my unit test for the baseDAO I get a null pointer exception when I try to get the sessionFactory from the HibernateTemplate that Spring wired for me.
It seems as if Spring isn't injecting the HibernateTemplate. But I can't see in the docs what else I need to do. I'm assuming that Spring can instantiate one of it's own classes as a bean and use DI to wire up the session factory.
I can't see the problem right now, can anyone tell me what I'm doing wrong?
Spring 1.1.5 (I think)
using HibernateTemplate (not Hibernate3)
Stack trace:
java.lang.NullPointerException
at sg.com.crownsys.promise.dao.implementation.BaseDAO Implementation.save(BaseDAOImplementation.java:164 )
at sg.com.crownsys.promise.dao.implementation.RoleDAO Implementation.saveRole(RoleDAOImplementation.java :44)
at sg.com.crownsys.promise.dao.test.BaseDAOImplementa tionTest.setUp(BaseDAOImplementationTest.java:26)
at junit.framework.TestCase.runBare(TestCase.java:125 )
at junit.framework.TestResult$1.protect(TestResult.ja va:106)
at junit.framework.TestResult.runProtected(TestResult .java:124)
at junit.framework.TestResult.run(TestResult.java:109 )
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:2 08)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.apache.tools.ant.taskdefs.optional.junit.JUnit TestRunner.run(JUnitTestRunner.java:289)
at org.apache.tools.ant.taskdefs.optional.junit.JUnit TestRunner.launch(JUnitTestRunner.java:656)
at org.apache.tools.ant.taskdefs.optional.junit.JUnit TestRunner.main(JUnitTestRunner.java:558)
Kev


Reply With Quote
