0

I am having problem with the execution of the Hibernate program . I am new to Hibernate.. Here is the error trace .. i received while executing the program

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

here is in hibernate configuration file 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>

and here is the main class

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 ");


    }

}

and finally the mapping file

<?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>

PLease can you point out the mistake i am doing here .... i am using eclipse to run the program and have also included the jar file from hibernate/lib/required and also included the jar file for jdbc from oracle and i am also connected to the internet. What i am missing here ..... ?

3 Answers 3

0

Try this:

!DOCTYPE hibernate-configuration SYSTEM "classpath://org/hibernate/hibernate-configuration-3.0.dtd"

It might resolve your issue.

If not try below will also work if your system is offline.

!DOCTYPE hibernate-configuration SYSTEM "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"

or you can see this link: org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml

or see this link: Can't parse hibernate.cfg.xml while offline

You might have the issue with database connection: check your database connection parameters

Sign up to request clarification or add additional context in comments.

2 Comments

i have edited more info to my answer. i hope it may answer your question.
I mostly did all the things in the sites mentioned and but still .. i am getting the same results
0

enter image description here

Click the button File System and find the DTD file in your hibernate jar files.The path is : hibernate3.jar\org\hibernate\hibernate-configuration-3.0.dtd

I wish it could help you and if you still can not solve the problem try the JPA annotation instead of the XML file.

1 Comment

i had used that but it didn't pan out. but now i was able to run the program and even insert into the table. Some of the required jar files where missing, which i included now
0

I found the reason why it was showing this error , as i was surfing yesterday for answer but didn't find the right one for this exact case. I am now able to run the file so i am posting the solution to the problem i faced yesterday. Hope it helps someone who is looking for it

Answer 1. Check all the required Jar file are there in the build path 2. for jdbc include the required jar file

JAR files name required from the hibernate folder while using the hibernate . Download the latest Hibernate from http://hibernate.org/orm/downloads/ or google Hibernate and click on the hibernate.org link . after downloading the folder will look something like thing

folder - hibernate-release-4.3.6.Final subfolders - 1. documentation 2. lib 3. project

first set of jar files ,go to hibernate-release-4.3.6.Final/lib/required add all the jar file in the list 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

in future if they add more jar or delete some from it but all the files in the required folder is a must

second set of jar files , go to hibernate-release-4.3.6.Final/lib/jpa only one jar file is there 1. hibernate-entitymanager-4.3.6.Final.jar

third and final set of jar files , go to hibernate-release-4.3.6.Final/lib/jpa-metamodel-generator 1. hibernate-jpamodelgen-4.3.6.Final.jar

so the final list of jar files 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

Plus the jdbc jar file for the required database oracle then.... ojdbc14.jar or something like that .. include that file as well .

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.