hibernate.cxf.xml 配置文件 解决 内容必须匹配 "(property*,mapping*,(classcachecollectioncache)*,event*,listener*)
来源:互联网 发布:阿里巴巴淘宝城 编辑:程序博客网 时间:2024/06/05 00:18
原网页地址:http://www.lxway.com/9144556.htm
这两天想看看hibernate的东西,就跟着官网教程自己做,被官网网页上的配置文件给坑了。
有两个注意的地方,如果是按照官网的筒子们注意啦,一个是hibernate的头xsd验证文件,不修改成dtd读取hibernate.cxf.xml会
抛出Could not parse configuration: /hibernate.cfg.xml或者org.hibernate.MappingException: invalid configuration异常的哦。
<hibernate-configuration xmlns="http://www.hibernate.org/xsd/hibernate-configuration" xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
6 改成下面的格式
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
还有的同学会抛出 元素类型为 “session-factory” 的内容必须匹配 “(property*,mapping*,(class-cachecollection-cache),event,listener*)”。
这个异常的原因可能有两个原因造成:
1.hibernate中配置文件的顺序写的有错误,按顺序配置<property>,<mapping> , <event>
和<listener>
标签如下:
注意property, mapping, event 和 listener 之间的顺序 <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost/hibernate</property> <mapping class="com.yami.hibernate.pojo.SingleUser" /> <mapping resource="org/hibernate/tutorial/domain/Event.hbm.xml"/> <event></event> <listener></listener>
2.如果不是顺序问题的话,就只有一个可能性了,你的配置文件可能是从网页上或者其他通过格式化工具拷贝的,有些编码没有转换,导致hibernate读取配置文件也会抛这个错误,下面就给一个可以用的配置文件(算是福利吗),
拷贝到自己的工程中再重新配置下就可以了:
<?xml version="1.0" encoding="utf-8" ?><!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd" ><hibernate-configuration> <session-factory> <!-- Database connection settings --> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost/hibernate</property> <property name="connection.username">erik</property> <property name="connection.password">test</property> <!-- JDBC connection pool (use the built-in) --> <property name="connection.pool_size">1</property> <!-- Disable the second-level cache --> <property name="cache.provider_class">org.hibernate.cache.internal.CollectionCacheInvalidator </property> <!-- Echo all executed SQL to stdout --> <property name="show_sql">true</property> <!-- Drop and re-create the database schema on startup --> <property name="hbm2ddl.auto">create</property> <!-- SQL dialect --> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <!-- Names the annotated entity class --> <mapping class="com.yami.hibernate.pojo.SingleUser" /> </session-factory></hibernate-configuration>
原以为hibernate官网上的例子应该没问题的,结果搞起来问题不断,太相信了官网上的代码了,弄了好久,才发现是xml的格式有问题。
一直以为是自己的配置文件哪里写错了,怎么看都没有找到问题,到最后才发现是自己拷贝了官网页面上的配置文件的格式有问题,看来有时候还是不能太相信官网呀。
- hibernate.cxf.xml 配置文件 解决 内容必须匹配 "(property*,mapping*,(classcachecollectioncache)*,event*,listener*)
- 元素类型为 "session-factory" 的内容必须匹配 "(property*,mapping*,(class-cach....解决方法
- hibernate中出现 文档根元素 "hibernate-mapping" 必须匹配 DOCTYPE 根 "hibernate-configuration"
- 文档根元素 "hibernate-mapping" 必须匹配 DOCTYPE 根 "hibernate-configuration"
- Hibernate的hibernate-mapping配置文件
- Hibernate配置文件报错:The content of element type "session-factory" must match "(property*,mapping*,(c
- 使用Hibernate时,hibernate.cfg.xml的配置文件内容
- org.hibernate.MappingException: duplicate property mapping:
- org.hibernate.MappingException: duplicate property mapping:
- 必须声明元素类型 "hibernate-mapping"
- hibernate映射配置文件(xxx.hbm.xml)内容及作用
- Mybatis配置文件报错“元素类型为 "configuration" 的内容必须匹配……”
- 错误整理(三)hibernate-configuration" 的内容必须匹配 "(session-factory,security?)
- struts.xml配置文件内容
- Event Listener)
- Listener event
- 解决 Mybatis 元素类型为 "resultMap" 的内容必须匹配 "(constructor?,id*,result*,association*,collection*,discriminat
- 解决 Mybatis 元素类型为 "resultMap" 的内容必须匹配 "(constructor?,id*,result*,association*,collection*,discriminat
- python学习之旅
- 【软考】——海明码和CRC码
- 经典算法题:无序整数数组中找第k大的数
- 智能的定义(二稿)
- Oracle_函数
- hibernate.cxf.xml 配置文件 解决 内容必须匹配 "(property*,mapping*,(classcachecollectioncache)*,event*,listener*)
- 【BZOJ】4614 [Wf2016] Oil
- ios 手动引入第三方库
- 求最长回文串(Manacher算法)
- 关于逆序对的两种做法(归并排序+树状数组c++)
- vs2013 编译 snmp++-3.3.7
- 20161027
- 转载特殊函数
- igb uio小结