aspose file tools*
The moose likes Object Relational Mapping and the fly likes session.flush() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "session.flush()" Watch "session.flush()" New topic
Author

session.flush()

saurabh jaju
Greenhorn

Joined: Mar 15, 2007
Posts: 1
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

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: session.flush()