-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Problem to run hibernate program
PostPosted: Mon Sep 24, 2012 5:15 am 
Newbie

Joined: Mon Sep 24, 2012 1:46 am
Posts: 2
Hello,

I am new in hibernate, just in the learning phase.
I am using eclipse indigo, hibernate, oracle 10g.
In my first programme got from internet during run the programme the below error I am getting -

Code:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
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 org.hibernate.cfg.Configuration.configure(Configuration.java:1411)
   at com.chinmoy.hibernate.StoreData.main(StoreData.java:18)
Caused by: org.dom4j.DocumentException: Connection timed out: connect Nested exception: Connection timed out: connect
   at org.dom4j.io.SAXReader.read(SAXReader.java:484)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481)



hibernate.cfg.xml:

Code:
<?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="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.password"><password></property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@172.24.70.12:1521:<db name></property>
        <property name="hibernate.connection.username"><user id></property>
        <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
        <mapping resource="Employee.hbm.xml"/>
    </session-factory>
</hibernate-configuration>



Controller class (StoreData):

Code:
package com.chinmoy.hibernate;   
 
 
import org.hibernate.Session;   
import org.hibernate.SessionFactory;   
import org.hibernate.Transaction;   
import org.hibernate.cfg.Configuration;   
 
public class StoreData {   
public static void main(String[] args) {   
       
    //creating configuration object   
    //Configuration cfg=new Configuration();   
       
    //cfg.configure("hibernate.cfg.xml");//populates the data of the configuration file   
       
    //creating seession factory object   
    //SessionFactory factory=cfg.buildSessionFactory();   
    SessionFactory factory=new Configuration().configure().buildSessionFactory();   
       
    //creating session object   
    Session session=factory.openSession();   
       
    //creating transaction object   
    //Transaction t=session.beginTransaction();   
           
    Employee e1=new Employee();   
    e1.setId(115);   
    e1.setFname("sonoo");   
    e1.setLname("jaiswal");   
       
    session.persist(e1);//persisting the object   
       
    //t.commit();//transaction is commited   
    session.close();   
       
    System.out.println("successfully saved");   
       
}   





I have add the below jar files -
antlr-2.7.6.jar
asm.jar
asm-attrs.jar
c3p0-0.9.1.jar
cglib-2.1.3.jar
commons-collections-2.1.1.jar
commons-logging-1.0.4.jar
dom4j-1.6.1.jar
ehcache-1.2.3.jar
ejb3-persistence.jar
hibernate3.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
hibernate-validator.jar
jdbc2_0-stdext.jar
jta.jar
log4j-1.2.11.jar
xerces-2.6.2.jar
ojdbc14.jar


Please help me to run the program.
This is a very simple basic program.


Top
 Profile  
 
 Post subject: Re: Problem to run hibernate program
PostPosted: Mon Sep 24, 2012 9:47 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Your java classpath must include the folder where you stored your hibernate.cfg.xml


Top
 Profile  
 
 Post subject: Re: Problem to run hibernate program
PostPosted: Tue Sep 25, 2012 4:54 am 
Newbie

Joined: Mon Sep 24, 2012 1:46 am
Posts: 2
Thanks for your suggestion.

I have created the hibernate.cfg.xml file into the src folder.
So, I think I did not need to set it in class path again.

The error is showing like - "Could not parse the file - hibernate.cfg.xml".
So, the xml file is found. So, class path does not need to be set again.

Please correct if I am wrong.


Top
 Profile  
 
 Post subject: Re: Problem to run hibernate program
PostPosted: Tue Sep 25, 2012 5:41 am 
Newbie

Joined: Wed May 05, 2004 1:00 pm
Posts: 7
Doesn't matter where you create the hibernate configuration/mappings, they should be available on the classpath. If you're using an IDE, find out to which directory the files are compiled and check if the hibernate configuration is in that directory.

For Eclipse: Right-click on your project, Properties, Java Build Path; look for the output folder.

Anyway, I think you may have this problem: http://forum.springsource.org/showthread.php?80886-How-to-configure-hibernate.cfg.xml-to-work-offline

Change the PUBLIC keyword into SYSTEM.


Last edited by ddecavele on Tue Sep 25, 2012 5:48 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Problem to run hibernate program
PostPosted: Tue Sep 25, 2012 5:41 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Looking again to the stacktrace you reported I see that the actual problem is a Connection timed out exception
which is probably due to the fact that the org.dom4j.io.SAXReader is trying to read
http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd (which is mentioned in your hibernate.cfg.xml)
through the Internet, which fails.
Does your machine have a internet connection?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.