I'm trying to use Hibernate and Spring together. I'm trying to run some tests through
JUnit.
I'll be glad to post more details, but I'm hoping this is simple enough of a problem that someone can give this noob an answer.
With my given configuration and classpath, my hibernate.cfg.xml appears to be loaded properly in the ApplicationContext, but the actual class mappings located in the same directory has hibernate.cfg.xml are not being loaded (via the mapping tag). I know hibernate.cfg.xml is found because when I change it's name, I get an exception saying it can't be found.
From hibernate.cfg.xml:
<mapping resource="EeActivity.hbm.xml"/>
<mapping resource="EeAction.hbm.xml"/>
<mapping resource="EeAlert.hbm.xml"/>
<mapping resource="EeAppDetailLngView.hbm.xml"/>
Here is my sessionFactory bean configuration from my Spring ApplicationContext.xml config:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource"><ref local="dataSource"/></property>
<property name="mappingResources">
<value>hibernate.cfg.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="eventListeners">
<map>
<entry key="merge">
<bean class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener"/>
</entry>
</map>
</property>
</bean>
Is there an initialization step I may be missing, or something else?
My bean extends HibernateDaoSupport (this is where I pull the application context).
This is the JUnit
Test method:
public void testRoleFindById(){
EeRole role = new EeRole();
role.setRoleId(new Integer(1));
RoleDAO roleDao = (RoleDAO)this.applicationContext.getBean("role");
try {
role = (EeRole)roleDao.find(role);
System.out.println("RoleName: " + role.getRoleName());
} catch (DaoException e) {
fail(e.toString());
}
}
Thanks,
David