Reputation: 13585
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>
Upvotes: 0
Views: 8850
Reputation: 11839
You can try the below code to point spring to correct location of hibernate.cfg.xml.
<bean
id="mySessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>
classpath:location_of_config_file/hibernate.cfg.xml
</value>
</property>
...........
</bean>
Upvotes: 0
Reputation: 11699
You have a forward slash at the beginning of your path, so you are looking in the root for it. This is almost certainly not correct.
<value>/master.hibernate.cfg.xml</value>
I normally specify my configuration like this:
<value>classpath:master.hibernate.cfg.xml</value>
This works if your master.hibernate.cfg.xml
is in your resources.
Upvotes: 1