0

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>

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.