Importing hibernate configuration file into Spring applicationContext
- by Himanshu Yadav
I am trying to integrate Hibernate 3 with Spring 3.1.0. The problem is that application is not able to find mapping file which declared in hibernate.cfg.xml file. Initially hibernate configuration has datasource configuration, hibernate properties and mapping hbm.xml files.
Master hibernate.cfg.xml file exist in src folder. this is how Master file looks:
<hibernate-configuration>
<session-factory>
<!-- Mappings -->
<mapping resource="com/test/class1.hbm.xml"/>
<mapping resource="/class2.hbm.xml"/>
<mapping resource="com/test/class3.hbm.xml"/>
<mapping resource="com/test/class4.hbm.xml"/>
<mapping resource="com/test/class5.hbm.xml"/>
Spring config is:
<bean id="sessionFactoryEditSolution" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="data1"/>
<property name="mappingResources">
<list>
<value>/master.hibernate.cfg.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
</props>
</property>
</bean>