• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session.flush()

 
saurabh jaju
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am getting a error in session.flush() and i am not able to resolve it ...please if anybody could help me out
---errors----

hibernate
before flush=========================================
Exception in thread "main" java.lang.NullPointerException
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:34)

----the firstexample.java-----

import org.hibernate.cfg.Configuration;

public class FirstExample {
public static void main(String[] args) {
Session session = null ;
System.out.println("hibernate");
try{
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
Transaction tx = session.beginTransaction();
//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("saurabh");
contact.setLastName("jaju");
contact.setEmail("saurabhjaju@gmail.com");
System.out.println("Done");
session.save(contact);
tx.commit();
System.out.println("Done");
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
// Actual contact insertion will happen at this step
System.out.println("before flush=========================================");
session.flush();
session.close();

}

}
}
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like your session is null. My guess is you are actually getting an exception at one of these lines:

so you are not getting asession in the first place.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic