简体   繁体   中英

Spring app cant find hbm.xml mapping file

I am working on a spring mvc app using hibernate and I am having some trouble compiling and running my code.

This is because it cannot find my FileObject.hbm.xml whenever I try to create a session factory bean.

my bean looks like this

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource1"></property>
    <property name="mappingResources">
        <list>
            <value>FileObject.hmb.xml</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.hbm2ddl.auto">create</prop>
        </props>
    </property>
</bean>

And the FileObject.hmb.xml resides in the root of my WAR folder. I have tried to move this file to different folders including the actual src folder and providing the correct path in the session factory but it still gives me a FileNotFoundException.

Is this because java doesnt recognise a hello.hmb.xml type of file? Most if not all file formats are like this: name.extension

hibernate mapping files seems to be different though

Follow-up: As I have noted before, I have tried to put my .hbm.xml in numerous places including the src directory and still wont work.

My project structure is similar to this:

项目结构
(source: springsource.org )

I have tried to put the file inside the root dir of war, WEB-INF, classes and as said before, in my actual src directory.

I never knew it was this much hassle just to get hibernate and spring running successfully.

MappingResources can only receive paths relative to your classpath.

http://forum.springsource.org/showthread.php?t=87988

If the .hbm.xml files are in a directory tree in your CLASSPATH, try putting the path starting from the root of the CLASSPATH:

<value>foo/bar/persistence/hibernate/FileObject.hmb.xml</value> 

Directory path I use is just an example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM