Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
    Bookmark Topic Watch Topic
  • New Topic

HI I got the null pointer exception using session factory

 
Bindu Sanju
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Report post to moderator
HI I got the exception while using this below code.

// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();

Configuration cfg = new Configuration();
cfg.addFile("/bin/hibernate.cfg.xml");
SessionFactory sesfact=(SessionFactory) cfg.configure().buildSessionFactory();
session=sesfact.openSession();

System.out.println("session : "+session);
//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Record");
Contact contact = new Contact();
contact.setId(6);
contact.setFirstName("Deepak");
contact.setLastName("Kumar");
contact.setEmail("deepak_38@yahoo.com");
session.save(contact);
System.out.println("Done");
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
// Actual contact insertion will happen at this step
session.flush();
session.close();


java.lang.NullPointerException
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:45)
Exception in thread "main"
 
    Bookmark Topic Watch Topic
  • New Topic