Hibernate: Exception in thread "main" java.lang.NullPointerException

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sophia Ranjani
    New Member
    • Aug 2012
    • 1

    Hibernate: Exception in thread "main" java.lang.NullPointerException

    I wrote a prgram using hibernate and got the following error:
    Exception in thread "main" java.lang.NullP ointerException
    at hibernateTutori al.FirstExample .main(FirstExam ple.java:36)
    /hibernate.cfg.x ml not found
    So i am new to this topic please help
    Thanks in advance.
    Please find the code attached below:

    public class FirstExample {


    public static void main(String[] args) {
    Session session = null;

    try{
    // This step will read hibernate.cfg.x ml


    SessionFactory sessionFactory = new

    Configuration() .configure().bu ildSessionFacto ry();
    session =sessionFactory .openSession();
    //Create new instance of Contact and set


    System.out.prin tln("Inserting Record");
    Contact contact = new Contact();
    contact.setId(3 );
    contact.setFirs tName("Deepak") ;
    contact.setLast Name("Kumar");
    contact.setEmai l("deepak_38@ya hoo.com");
    session.save(co ntact);
    System.out.prin tln("Done");
    }catch(Exceptio n e){
    System.out.prin tln(e.getMessag e());
    }finally{
    // Actual contact insertion will happen at this step
    session.flush() ;
    session.close() ;
Working...