• 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
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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:

 
Everybody's invited. Even this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic