【问题标题】:Hibernate exception eclipse休眠异常日食
【发布时间】: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


    【解决方案1】:

    试试这个:

    !DOCTYPE 休眠配置系统 "classpath://org/hibernate/hibernate-configuration-3.0.dtd"

    它可能会解决您的问题。

    如果您的系统处于脱机状态,则下面的尝试也可以使用。

    !DOCTYPE 休眠配置系统 "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"

    或者你可以看到这个链接: org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml

    或查看此链接: Can't parse hibernate.cfg.xml while offline

    您可能遇到数据库连接问题:检查您的数据库连接参数

    【讨论】:

    • 我已经为我的答案编辑了更多信息。我希望它能回答你的问题。
    • 我大部分时间都在提到的网站上做了所有事情,但仍然......我得到了相同的结果
    【解决方案2】:

    点击文件系统按钮,在你的hibernate jar文件中找到DTD文件。路径是: hibernate3.jar\org\hibernate\hibernate-configuration-3.0.dtd

    我希望它可以帮助您,如果您仍然无法解决问题,请尝试使用 JPA 注释而不是 XML 文件。

    【讨论】:

    • 我用过,但没有成功。但现在我能够运行该程序,甚至可以插入到表中。缺少一些必需的 jar 文件,我现在包含了这些文件
    【解决方案3】:

    我找到了显示此错误的原因,因为我昨天在网上寻找答案,但没有找到适合这种情况的正确答案。我现在可以运行该文件,因此我发布了昨天遇到的问题的解决方案。希望对正在寻找它的人有所帮助

    回答 1.检查所有需要的Jar文件是否在构建路径中 2.对于jdbc,包含需要的jar文件

    使用 hibernate 时需要来自 hibernate 文件夹的 JAR 文件名。从 http://hibernate.org/orm/downloads/ 或谷歌 Hibernate 下载最新的 Hibernate 并单击 hibernate.org 链接。下载文件夹后会看起来像这样的东西

    文件夹 - hibernate-release-4.3.6.Final 子文件夹 - 1. 文档 2.库 3. 项目

    第一组jar文件,进入hibernate-release-4.3.6.Final/lib/required 添加列表中的所有jar文件 1.antlr-2.7.7.jar 2.dom4j-1.6.1.jar 3.hibernate-commons-annotations-4.0.5.Final.jar 4.hibernate-core-4.3.6 .Final.jar 5.hibernate-jpa-2.1-api-1.0.0.Final.jar 6.jandex-1.1.0.Final.jar 7.javassist-3.18.1-GA.jar 8.jboss-logging-3.1 .3.GA.jar 9.jboss-logging-annotations-1.2.0.Beta1.jar 10. jboss-transaction-api_1.2_spec-1.0.0.Final.jar

    将来如果他们添加更多 jar 或从中删除一些但所需文件夹中的所有文件都是必须的

    第二组jar文件,去hibernate-release-4.3.6.Final/lib/jpa只有一个jar文件1.hibernate-entitymanager-4.3.6.Final.jar

    第三组也是最后一组jar文件,进入hibernate-release-4.3.6.Final/lib/jpa-metamodel-generator 1.hibernate-jpamodelgen-4.3.6.Final.jar

    所以最终的jar文件列表 1.1.antlr-2.7.7.jar 2.dom4j-1.6.1.jar 3.hibernate-commons-annotations-4.0.5.Final.jar 4.hibernate-core-4.3.6.Final.jar 5.hibernate- jpa-2.1-api-1.0.0.Final.jar 6.jandex-1.1.0.Final.jar 7.javassist-3.18.1-GA.jar 8.jboss-logging-3.1.3.GA.jar 9. jboss-logging-annotations-1.2.0.Beta1.jar 10. jboss-transaction-api_1.2_spec-1.0.0.Final.jar

    加上所需数据库 oracle 的 jdbc jar 文件,然后...... ojdbc14.jar 或类似的东西......也包括该文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-14
      • 2014-08-22
      • 2011-09-20
      • 2017-07-06
      • 2012-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多