实际上我正在尝试进行休眠日志记录。这是我的 hibernate.cfg.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">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="hbm2ddl.auto">update</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="connection.url">jdbc:oracle//localhost/5432/newdatabase</property>
<property name="connection.username">postgres</property>
<property name="connection.password">P@ssword</property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<mapping resource="employee.hbm.xml"/>
</session-factory>
</hibernate-configuration>
这是我的主要课程
package com.javatpoint;
import org.hibernate.*;
import org.hibernate.cfg.*;
public class StoreData {
public static void main(String[] args) {
Configuration cfg=new Configuration();
cfg.configure("hibernate.cfg.xml");
SessionFactory factory=cfg.buildSessionFactory();
Session session=factory.openSession();
Transaction tx=session.beginTransaction();
session.save(new Employee("Arun",3800));
session.save(new Employee("Varun",4800));
tx.commit();
session.close();
System.out.println("record successfully persisted");
}
}
当我运行它时,我收到以下错误。
Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1491)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)
at com.javatpoint.StoreData.main(StoreData.java:9)
Caused by: org.dom4j.DocumentException: hibernate.sourceforge.net Nested exception: hibernate.sourceforge.net
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481)
... 2 more
经过大量谷歌搜索后,我才知道它与 DOCTYPE 相关。但即便如此,我也无法为此找到完美的解决方案。有人可以帮我吗。?谢谢。