您的位置:首页 > 其它

hibernate中不能解析hbm.xml的问题

2013-01-19 12:34 155 查看
异常信息:

Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [E:\My Code\j2ee\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\DigitalFamily\WEB-INF\classes\config\spring-applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.InvalidMappingException: Could not parse mapping document from file E:\My Code\j2ee\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\Test\WEB-INF\classes\com\test\model\security\Authority.hbm.xml


出错的xml文件:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2013-1-16 22:46:12 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.test.model.security.Authority" table="DF_AUTHORITY">
<id name="id" type="int">
<column name="[ID]" />
<generator class="identity" />
</id>
<property name="name" type="java.lang.String">
<column name="[NAME]" />
</property>
<property name="desc" type="java.lang.String">
<column name="[DESC]" />
</property>
<property name="status" type="int">
<column name="[STATUS]" />
</property>
<set name="resources" table="RESOURE" inverse="false" lazy="true">
<key>
<column name="[RESOURCE_ID]" />
</key>
<one-to-many class="com.test.model.security.Resoure" />
</set>
</class>
</hibernate-mapping>


这是hibernate tool自动生成的文件,按理说是不应该有错的。

这是applicationContext.xml片段:

<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingDirectoryLocations">
<list>
<value>classpath:com/test/model/security</value>
<value>classpath:com/test/model</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
hibernate.hbm2ddl.auto=update
</value>
</property>
</bean>


纠结了好久终于找到了问题,mappingDirectoryLocations下的配置每个路径,hibernate都会去找它的子目录的,因此<value>classpath:com/test/model</value>中其实就已经包含了<value>classpath:com/test/model/security</value>,删掉后者即可...

另外大多数时候出现这个错误是因为在把configuration和mapping这两个dtd弄混了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐