wood burning stoves
The moose likes Object Relational Mapping and the fly likes NullPointerException in session.flush() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "NullPointerException in session.flush()" Watch "NullPointerException in session.flush()" New topic

NullPointerException in session.flush()

vinoth subramaniam
Ranch Hand

Joined: Jul 05, 2008
Posts: 47
Hi all, i am getting the NullPointerException in my application. Please Help me to solve this.

Here is the hibernate.cfg.xml


Here is the contact.hbm.xml


Here is the java file inserting the record to the databse


And i am getting the following error at the line "session.flush();"

Exception in thread "main" java.lang.NullPointerException
at com.tcs.lamda.POC.hibernate.FirstExample.main(FirstExample.java:33)

Please help me to solve this issue. Please ask if you need any further information.
Don Solomon
Ranch Hand

Joined: Jul 20, 2008
Posts: 48
never used this stuff in my life.

i would put "Contact contact=null" before the try block. then "contact=new Contact()" inside the try block. Contact has gone out of scope in your finally.

Software development is an exercise in thinking not coding.
Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10441

Probably your session object never got created in the try block. Your catch block is eating the actual exception:

At the very least, i would do a e.printStackTrace() in the catch block to see the actual error.

And also your finally block can be improved to do a null check:

[My Blog] [JavaRanch Journal]
I agree. Here's the link: http://aspose.com/file-tools
subject: NullPointerException in session.flush()
It's not a secret anymore!