为了账号安全,请及时绑定邮箱和手机立即绑定

hibernated.cfg.xml报错问题,快崩溃了。。。

两个hibernate.cfg.xml文件一模一样,可是一个总是报错,另外一个就没报错可以正常运行,我把两个文件一个单词一个单词的对照实在是照找不出错误,求大神帮忙看下。

文件A

<?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>
		<property name="hibernate.connection.username">root</property>		
        <property name="hibernate.connection.password"></property>              
        <property name="hibernate.connection.url">
        	<![CDATA[
        		jdbc:mysql://localhost:3306/webdata?useUnicode=true&characterEncoding=utf8
        	]]>
        </property>
        
		<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        
		<property name="show_sql">true</property>
        <property name="hbm2ddl.auto">update</property>
        
        <mapping resource="com/bart/entity/Seller.hbm.xml"/>
        <mapping resource="com/bart/entity/Student.hbm.xml"/>
	</session-factory>
</hibernate-configuration>

文件B:

<?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>
  	<property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password"></property>
        <property name="hibernate.connection.url">
        	<![CDATA[
        		jdbc:mysql://localhost:3306/webdata?useUnicode=true&characterEncoding=utf8
        	]]>
        </property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        
        <property name="show_sql">true</property>
        <property name="hbm2ddl.auto">update</property>
    
    	<!-- 指定映射文件的路径 -->
    	<mapping resource="com/bart/entity/Student.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

这时A和B的内容,A一直报错,我全选A文件删除然后粘贴为B文件就不报错了。太奇怪了。。。开发环境是MyEclipse 10,Hibernate包是4.3的

报错信息:

WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!

2016-9-18 12:45:13 org.hibernate.cfg.Configuration addResource

INFO: HHH000221: Reading mappings from resource: com/bart/entity/Seller.hbm.xml

2016-9-18 12:45:13 org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity

WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!

Exception in thread "main" java.lang.ExceptionInInitializerError

at com.bart.test.Test01.add(Test01.java:26)

at com.bart.test.Test01.main(Test01.java:14)

Caused by: org.hibernate.InvalidMappingException: Unable to read XML

at org.hibernate.internal.util.xml.MappingReader.legacyReadMappingDocument(MappingReader.java:375)

at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:304)

at org.hibernate.cfg.Configuration.add(Configuration.java:516)

at org.hibernate.cfg.Configuration.add(Configuration.java:512)

at org.hibernate.cfg.Configuration.add(Configuration.java:686)

at org.hibernate.cfg.Configuration.addResource(Configuration.java:769)

at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2255)

at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2227)

at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2207)

at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2160)

at org.hibernate.cfg.Configuration.configure(Configuration.java:2075)

at org.hibernate.cfg.Configuration.configure(Configuration.java:2054)

at com.bart.util.HibernateUtil.<clinit>(HibernateUtil.java:20)

... 2 more

Caused by: org.dom4j.DocumentException: Error on line 8 of document  : Attribute name "column" associated with an element type "id" must be followed by the ' = ' character. Nested exception: Attribute name "column" associated with an element type "id" must be followed by the ' = ' character.

at org.dom4j.io.SAXReader.read(SAXReader.java:482)

at org.hibernate.internal.util.xml.MappingReader.legacyReadMappingDocument(MappingReader.java:325)

... 14 more


正在回答

1 回答

终于找到问题所在了。。。粗心粗心粗心!!!

A文件比B文件多了一个mapping resource

<mapping resource="com/bart/entity/Seller.hbm.xml"/>

敲好Seller.hbm.xml文件出错。。导致报错。。。

0 回复 有任何疑惑可以回复我~
#1

Mark_G 提问者

去掉<mapping resource="com/bart/entity/Seller.hbm.xml"/>后A文件和B文件一样正确运行了。。。因为SessionFactory在解析hibernate.cfg.xml文件的时候会解析里面 的 所有的<mapping resource=“XXX”>标签的源文件,如果有一个出错,就会报错的
2016-09-18 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

hibernated.cfg.xml报错问题,快崩溃了。。。

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信