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.
精彩评论