• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

NullPointerException in session.flush()

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
mooooooo ..... tiny ad ....
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic