wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Problem with the sample hibernate program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Problem with the sample hibernate program" Watch "Problem with the sample hibernate program" New topic
Author

Problem with the sample hibernate program

Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
Dear all,

Earlier had worked with hibernate framework with oracl and mysql database. Now I am trying the same with the Postgres database. But I am not able to save the data. Please find my files below:

hibernate config xml file:




student.hbm.xml file :



SaveDemo.java




Cheers,
Keerthi Kumar N
Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
Dear all,

I am able to get a connection to the postgres database as well. But when I execute the main class (SaveDemo.java), the values are not being inserted into the db. Also I am not getting any errors or exception for the same.

Request you all to help me out in this.
Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
You have opened a transaction. However, there is no transaction commit or close done in your code. Have you posted the complete code?
Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
Hi Sridhar,

I had added that trans.commit() in the finally block. But it was throwing some error Hence i removed that line. Please help me out.
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

Without committing the data will not be inserted.. Can you tell us what error you were getting when you added that
trans.commit ()


Regards, Prasad
SCJP 5 (93%)
vijin das
Ranch Hand

Joined: Jun 07, 2010
Posts: 129

put trans.commit() in the try block itself after session.save() .... try this code ..and test



VIJINDAS
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

...though of course, if calling commit() in the finally block is " throwing some error " moving it to the catch block is unlikely to fix this. What is the error?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
Hi,

Thanks a lot It is working fine now
Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
Dear All,

Once again stuck up with a small issue.But I am not able to figure it out. In the previously mentioned code snippet, when the control invokes the below line of code, the control is directly moving to the session.close() method of the finally block :



Request to help me to solve this issue.
Christian Dillinger
Ranch Hand

Joined: Jul 20, 2009
Posts: 188
When it's moving to the finally-bock without printing some of the System.outs you have in there, there should be a stacktrace which might help us a little bit...
Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
Dear,

After coming to session.close() of the finally block, it is just printing null pointer exception at the line of session.close()
Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
Dear all,

Below is the error I am getting while trying to execute the above give program:



Please help me out to resolve this issue.
Christian Dillinger
Ranch Hand

Joined: Jul 20, 2009
Posts: 188
As you didn't post the code of your program, we cannot know whats in line 53. I think it is "session.close()" which is inside a finally block. Something went wrong opening the connection, a runtime exception occured which you re-throw. After that the finally-block is being processed where the NPE occurs because the session is null. But as you didn't post the stacktrace of the exception we cannot know, what happened exactly. There MUST be a stacktrace. You could print it right before re-throwing the RuntimeException.
Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
Dear all,

I just changed the asm.jar and cglib.jar to the latest versions. It worked fine. Thanks to you all for your valuable support and guidance.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem with the sample hibernate program
 
Similar Threads
java.lang.NoClassDefFoundError
exception getting while running a Hibernate program
NullPointerException at the SessionFactory create line.
Hibernate Dialect for MS Access
problem with hibernate