Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException in session.flush()

 
vinoth subramaniam
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic