Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Odd NullPointerException

 
subhashchandra medhiassam
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear friends,
I have run into a problem and need your help in solving it.

I am trying to map the values of the fields of an object into a relational database table.

The file hibernate.cfg.xml looks like the following :



The POJO class named ContactDetails.java looks like the following :




And the class used to set the values into the POJO is named as FirstExample.java. It looks like the following:


But when i execute FirstExample.java, i am getting a NulPointerException corresponding to the statement session.flush(); which is in the finally block.
What should i do now ? Kindly help me out.


Subhash
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So most likely your session is not created in the first place. Have a look at your logs, there should be another error message in there.
 
subhashchandra medhiassam
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have sorted out the problem. I had not included some of the jars. Thanks for the help anyway.

Subhash
 
Lei Guoguo
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
subhashchandra medhiassam wrote:Dear friends,


But when i execute FirstExample.java, i am getting a NulPointerException corresponding to the statement session.flush(); which is in the finally block.
What should i do now ? Kindly help me out.


Subhash


you can try in this way:

......
finally {
if(session != null) {
session.flush();
session.close();
session = null;
}
}
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!