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