【发布时间】:2014-09-11 13:42:18
【问题描述】:
我在执行 Hibernate 程序时遇到问题。我是新来的休眠.. 这是错误跟踪..我在执行程序时收到的
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 store_h1.main(store_h1.java:15)
Caused by: org.dom4j.DocumentException: Connection reset Nested exception: Connection reset
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481)
... 2 more
这里是hibernate配置文件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">
<hibernate-configuration>
<session-factory>
<property name="hbm2ddl.auto">update</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1522:xe</property>
<property name="connection.username">swapnil</property>
<property name="connection.password">swapnil</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="show_sql">true</property>
<mapping resource="h1.hbm.xml"/>
</session-factory>
</hibernate-configuration>
这里是主类
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.*;
public class store_h1 {
public static void main(String[] args) {
//create configuration object
Configuration cfg = new Configuration();
cfg.configure("hibernate.cfg.xml");
//create session factory object
SessionFactory factory = cfg.buildSessionFactory();
//create session object
Session session= factory.openSession();
//create Transaction object
Transaction t = session.beginTransaction();
h1 h = new h1();
h.set_id(30);
h.set_first("something");
h.set_last("Hibernate");
session.persist(h);
t.commit();
session.close();
System.out.println("Sucessfully Hibernate used for storing data ");
}
}
最后是映射文件
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name = "h1" table="t1">
<--<id name="empid"></id>-->
<property name="empid"></property>
<property name="first_name"></property>
<property name="last_name"></property>
</class>
</hibernate-mapping>
请您指出我在这里做的错误....我正在使用 eclipse 运行程序,并且还包含了 hibernate/lib/required 中的 jar 文件,还包含了 oracle 中的 jdbc jar 文件和我也连接到互联网。我在这里想念什么.....?
【问题讨论】:
标签: java hibernate exception hibernate-mapping