执行我的 java 代码后出现以下错误。似乎只有 XML 文件有问题。所以,我没有发布Java代码。错误后给出了 XML 代码。我照原样从我的书中复制它,但它会导致错误。我该如何纠正这个恼人的 xml 错误?
"Some value of time" org.hibernate.cfg.annotations.Version <clinit>
INFO: Hibernate Annotations 3.3.1.GA
[main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
[main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
[main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
[main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
[main] INFO org.hibernate.cfg.Configuration - configuring from resource:
/hibernate.cfg.xml
[main] INFO org.hibernate.cfg.Configuration - Configuration resource:
/hibernate.cfg.xml
[main] ERROR org.hibernate.util.XMLHelper - Error parsing XML:
/hibernate.cfg.xml(3)
The markup in the document preceding the root element must be well-formed.
Exception in thread "main" org.hibernate.HibernateException: Could not parse
configuration: /hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1542)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure
(AnnotationConfiguration.java:990)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure
(AnnotationConfiguration.java:69)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
at org.hibernate.cfg.AnnotationConfiguration.configure
(AnnotationConfiguration.java:972)
at org.hibernate.cfg.AnnotationConfiguration.configure
(AnnotationConfiguration.java:69)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
at org.hibernate.cfg.AnnotationConfiguration.configure
(AnnotationConfiguration.java:966)
at com.examscam.model.User.persist(User.java:47)
at com.examscam.model.User.main(User.java:57)
Caused by: org.dom4j.DocumentException: Error on line 3 of document : The markup
in the document preceding the root element must be well-formed. Nested exception:
The markup in the document preceding the root element must be well-formed.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1532)
... 9 more
XML文件如下 -
<?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 = "connection.url">
jdbc:mysql://localhost/examscam
</property>
<property name = "connection.username">
root
</property>
<property name = "connection.password">
password
</property>
<property name = "connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name = "dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name = "transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<property name = "current_session_context_class">
thread
</property>
<property name = "hibernate.show_sql">
true
</property>
</session-factory>
</hibernate-configuration>
编辑
org.hibernate.cfg.annotations.Version <clinit>
INFO: Hibernate Annotations 3.3.1.GA
[main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
[main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
[main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
[main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
[main] INFO org.hibernate.cfg.Configuration - configuring from resource:
/hibernate.cfg.xml
[main] INFO org.hibernate.cfg.Configuration - Configuration resource:
/hibernate.cfg.xml
[main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource :
com/xx /portal/db/User.hbm.xml
Exception in thread "main" org.hibernate.MappingNotFoundException: resource: com/xx
/portal/db/User.hbm.xml not found
at org.hibernate.cfg.Configuration.addResource(Configuration.java:610)
at org.hibernate.cfg.AnnotationConfiguration.addResource
(AnnotationConfiguration.java:912)
at org.hibernate.cfg.AnnotationConfiguration.parseMappingElement
(AnnotationConfiguration.java:617)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure
(AnnotationConfiguration.java:1002)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure
(AnnotationConfiguration.java:69)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure
(AnnotationConfiguration.java:990)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure
(AnnotationConfiguration.java:69)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
at org.hibernate.cfg.AnnotationConfiguration.configure
(AnnotationConfiguration.java:972)
at org.hibernate.cfg.AnnotationConfiguration.configure
(AnnotationConfiguration.java:69)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
at org.hibernate.cfg.AnnotationConfiguration.configure
(AnnotationConfiguration.java:966)
at com.examscam.model.User.persist(User.java:45)
at com.examscam.model.User.main(User.java:55)