hibernate中不能解析hbm.xml的问题
2013-01-19 12:34
155 查看
异常信息:
出错的xml文件:
这是hibernate tool自动生成的文件,按理说是不应该有错的。
这是applicationContext.xml片段:
纠结了好久终于找到了问题,mappingDirectoryLocations下的配置每个路径,hibernate都会去找它的子目录的,因此<value>classpath:com/test/model</value>中其实就已经包含了<value>classpath:com/test/model/security</value>,删掉后者即可...
另外大多数时候出现这个错误是因为在把configuration和mapping这两个dtd弄混了
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弄混了
相关文章推荐
- Hibernate 未联网情况下不能根据dtd解析hbm.xml
- SSH框架问题——hbm.xml配置出现的org.hibernate.MappingException: Could not determine type for:(貌似叫数据类型转换错误)问题
- 关于hibernate纯sql查询返回结果集的问题(hbm.xml中不写多表关联)
- Java XML中配置dubbo相关标签不能解析的问题
- hibernate的 hbm.xml 需要注意的问题
- Hibernate 中 .hbm.xml映射文件 路径问题
- 碎碎念:IE下不能正确解析xml文件的问题
- XML中配置dubbo相关标签不能解析的问题
- maven项目中 org.hibernate.MappingNotFoundException: resource:**.hbm.xml not found问题的解决方案
- struts.xml中的default-action-ref解决不能解析网址问题
- hibernate 不能解析hibernate.cfg.xml 文件
- 关于hibernate纯sql查询返回结果集的问题(hbm.xml中不写多表关联)
- hibernate中写配置文件xxx.hbm.xml时那个成员变量的类型type如何写的问题
- maven项目中 org.hibernate.MappingNotFoundException: resource:**.hbm.xml not found问题的解决方案
- 【原创】解决jquery在ie中不能解析字符串类型xml结构的xml字符串的问题
- 用eclipse配置hibernate的hbm.xml文件时遇到的一些问题
- wap实践问题1-Opera浏览器上不能解析xml
- [原创]java WEB学习笔记77:Hibernate学习之路---Hibernate 版本 helloword 与 解析,.环境搭建,hibernate.cfg.xml文件及参数说明,持久化类,对象-关系映射文件.hbm.xml,Hibernate API (Configuration 类,SessionFactory 接口,Session 接口,Transaction(事务))
- 表的映射文件问题,javaweb+hibernate , .hbm.xml
- Hibernate4.1不能读取XML的问题