Win a copy of Spark in Action this week in the Open Source Projects forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Hibernate

 
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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE 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
Hibernate Eclipse IDE 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?
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic