我对休眠非常陌生,我创建了一个非常基本的示例,但是当我尝试运行此应用程序时,xml 解析错误即将到来。我已经为资源创建了一个包,我在其中保存了Employee.hbm.xml
Eclipse 中的 src 文件夹,我保存了hibernate.cfg.xml
这是我的错误
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Initial SessionFactory creation failed.org.hibernate.HibernateException: problem parsing configuration/com/nousinfo/resource
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.nousinfo.tutorial.utils.HibernateUtil.buildSessionFactory(HibernateUtil.java:17)
at com.nousinfo.tutorial.utils.HibernateUtil.<clinit>(HibernateUtil.java:7)
at com.nousinfo.tutorial.dao.impl.EmployeeDAO.<clinit>(EmployeeDAO.java:15)
at main.hibernatetest.main(hibernatetest.java:30)
Caused by: org.hibernate.HibernateException: problem parsing configuration/com/nousinfo/resource
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1222)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1161)
at com.nousinfo.tutorial.utils.HibernateUtil.buildSessionFactory(HibernateUtil.java:12)
... 3 more
Caused by: org.dom4j.DocumentException: Error on line 1 of document : Content is not allowed in prolog. Nested exception: Content is not allowed in prolog.
at org.dom4j.io.SAXReader.read(SAXReader.java:350)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217)
... 5 more
这是我的 hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name=hibernate.dialect ">
org.hibernate.dialect.MySQLDialect
</property-name>
<property name=hibernate.connection.driver_class ">
com.mysql.jdbc.Driver
</property-name>
<property name=hibernate.connection.url ">
jdbc:mysql://192.168.25.30:3306/employee
</property-name>
<property name=hibernate.connection.username ">
jack
</property-name>
<property name=hibernate.connection.password ">
jack1234
</property-name>
<property name="show_sql">
true
</property>
<property name="connection.autocommit">
true
</property>
<!-- List of XML mapping files -->
<mapping resource="com/nousinfo/resource/Employee.hbm.xml" />
</session-factory>
</hibernate-configuration>
这是我的 Employee.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Employee" table="EMPLOYEE">
<meta attribute="class-description">
This class contains the employee detail
</meta>
<id name="employeeNumber" type="int" column="EMPLOYE_NUMBER">
<generator class="native" />
</id>
<property name="firstName" type="string" column="FIRST_NAME" />
<property name="lastName" type="string" column="LAST_NAME" />
<property name="title" type="string" column="TITLE" />
<property name="departmentId" type="string" column="DEPARTMENT_ID" />
<property name="address1" type="string" column="ADDRESS_1" />
<property name="address2" type="string" column="ADDRESS_2" />
<property name="city" type="string" column="CITY" />
<property name="state" type="string" column="STATE" />
<property name="pincode" type="int" column="PINCODE" />
<property name="telephoneNumber" type="int" column="TELEPHONE_NUMBER" />
<property name="mobileNumber" type="int" column="MOBILE_NUMBERr" />
<property name="dateOfBirth" type="date" column="DATE_OF_BIRTH" />
<property name="dateOfAnniversary" type="date" column="DATE_OF_ANNIVERSARY" />
<property name="dateOfJoining" type="date" column="DATE_OF_JOINING" />
<property name="dateOfLeaving" type="date" column="DATE_OF_LEAVING" />
<property name="reasonForLeaving" type="string" column="REASON_FOR_LEAVING" />
</class>
</hibernate-mapping>