• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with the sample hibernate program

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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



 
Keerthi Kumar
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without committing the data will not be inserted.. Can you tell us what error you were getting when you added that
trans.commit ()
 
Ranch Hand
Posts: 129
Firefox Browser Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
put trans.commit() in the try block itself after session.save() .... try this code ..and test

 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...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?
 
Keerthi Kumar
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks a lot It is working fine now
 
Keerthi Kumar
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
PI day is 3.14 (march 14th) and is also einstein's birthday. And this is merely a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic