-->
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: org.hibernate.HibernateException: /hibernate.cfg.xml not fo
PostPosted: Sat Dec 16, 2006 4:52 am 
Newbie

Joined: Sat Dec 16, 2006 4:14 am
Posts: 3
Hi ,

I am Madhavi.I was new to hibernate.I am developing hibernate through Eclipse.

My requirement is to data into the database. IN the IDE there is No error But ,When i run the application i am getting the Error

Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1287)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1309)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1296)
at org.classes.getter.main(getter.java:15)

my java class is geeter.java, this is the code of my java file

ackage org.classes;
import org.hibernate.Session;
import org.hibernate.*;
import org.hibernate.cfg.*;

public class getter {

/**
* @param args
*/
public static void main(String[] args) throws Exception
{
Session session;
Configuration conf=new Configuration();
conf.configure();
SessionFactory sessionFactory =conf.buildSessionFactory();
session =sessionFactory.openSession();
System.out.println("session started");
try
{

Transaction tx=session.beginTransaction();
System.out.println("transaction started");
org.data.SecondId so=new org.data.SecondId();
System.out.println("Instance created");
// so.setId("1003");
so.setName("latha");
tx.commit();
System.out.println("end");

}

catch(Exception e)
{
System.out.println("Exception......" +e);
}

session.close();
}

}

If any one know the answer please give me the solution.


thank you,
madhavi.


Top
 Profile  
 
 Post subject: classpath
PostPosted: Sat Dec 16, 2006 9:23 pm 
Beginner
Beginner

Joined: Thu Apr 27, 2006 12:19 pm
Posts: 33
Location: Seattle, WA
Is hibernate.cfg.xml in your classpath?


Top
 Profile  
 
 Post subject: RTFM
PostPosted: Sat Dec 16, 2006 11:21 pm 
Beginner
Beginner

Joined: Sat Dec 16, 2006 9:53 pm
Posts: 31
Location: Brisbane, Australia
Madhavi,

Section 1.2.3. Hibernate configuration of the user manual says
the manual wrote:
Copy this file [hibernate.cfg.xml] into the source directory, so it will end up in the root of the classpath. Hibernate automatically looks for a file called hibernate.cfg.xml in the root of the classpath, on startup.


Hope this helps. Keith.


Top
 Profile  
 
 Post subject: Yes
PostPosted: Mon Dec 18, 2006 2:23 am 
Newbie

Joined: Sat Dec 16, 2006 4:14 am
Posts: 3
Thank you,

My probel has been solved , But the data i am entering into the database is not visible into the databse.i am sending my code.

public class generate {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Session session;
Configuration conf=new Configuration();
conf.configure();
SessionFactory sessionFactory =conf.buildSessionFactory();
session =sessionFactory.openSession();
System.out.println("session started");
try
{
Transaction tx=session.beginTransaction();
System.out.println("transaction started");
org.pojo.Madhu so=new org.pojo.Madhu();
System.out.println("Instance created");
//so.setId("1003");
so.setName("hari");
so.setName("madhavi");
so.setName("radha");
String abc=so.getName();
System.out.println("..........." +abc);
tx.commit();
System.out.println("end");

}

catch(Exception e)
{
System.out.println("Exception......" +e);
}
session.close();

}

}


Top
 Profile  
 
 Post subject: session association
PostPosted: Tue Dec 19, 2006 3:16 pm 
Beginner
Beginner

Joined: Thu Apr 27, 2006 12:19 pm
Posts: 33
Location: Seattle, WA
You need to associate your so instance with the Hibernate session.

// create instance
org.data.SecondId so=new org.data.SecondId();
so.setName("latha");

// associate instance with session
session.save(so);


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.