Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate

 
Reshma Reddy
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to All,
i am doing simple hibernate applications when i run my application in eclipse it is not recognising my cfg.xml file i think my application context root is not correct please tell me where i have to keep my xml files and where i have to keep java files tell me that context root for any hibernate application, thanks in advance

Thanks,
vishnu.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hibernate.cfg.xml should be in the root directory of your class files (unless you configure it otherwise). Where have you put it? Can you show us the code you use to create your SessionFactory?
 
Reshma Reddy
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi this my SessonFactory class

package src.example;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;


public class FirstExample {

/**
* @param args
*/
public static void main(String[] args) {
/**
* TODO Auto-generated method stub
* Simple Hibernate Example
*/
Session session = null;

try{
Configuration configaration = new Configuration();
Configuration config = configaration.configure();
//SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
SessionFactory sessionFactory = config.buildSessionFactory();
session = sessionFactory.openSession();

//opening session

System.out.println("insert values in to table");
Honey honey= new Honey();
honey.setId(2);
honey.setName("abc");
honey.setTaste("ok");
session.save(honey);
System.out.println("insertion is over");
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
//session.flush();
//session.close();
}
}
}
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, so you are just using the default configuration in which case hibernate.cfg.xml should be at the root directory where your classes are. Is it?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic