-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: How to reload an object within the same session?
PostPosted: Fri Dec 12, 2008 8:14 am 
Newbie

Joined: Fri Dec 12, 2008 8:07 am
Posts: 3
Hello,

I am working on a web based Struts application with MySQL hosted on Tomcat. I use Hibernate 3.1 for my ORM and I seem to have run into a problem.

During an operation I retrieve an object from the database and within the same operation I have to retrieve the same object again from the database. The first retrieval works fine without any issues, but the second retrieval cant seem to find the data.

I'm still a newbie when it comes to Hibernate session handling and I was wondering if any of you could tell me what I am doing wrong!

Thanks
G


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 12, 2008 9:43 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
From API documentation:

Quote:
Session.refresh(): Re-read the state of the given instance from the underlying database.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 19, 2008 1:32 pm 
Newbie

Joined: Fri Dec 12, 2008 8:07 am
Posts: 3
Thanks for the reply.

My problem is this, when a user comes in he needs to submit his order. The system is supposed to accept the order and then adjust the other elements in its database. For this it tries to load up certain entities twice within the same session.

It succeeds in retrieving the object the first time, but the second time it fails to retrieve the object! What am I doing wrong please?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 19, 2008 2:32 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
What am I doing wrong please?


Kind of hard to answer that since you don't tell us what you are doing. How do you retrieve the object? Are you, for example, using Session.get(), Session.load(), a HQL query, a critera query, etc? What kind of failure do you get? Exceptions? Any log/debug output?

In any case, a single Session can only hold one reference to the same entity. Use Session.refresh() to re-read the info from the database into the same entity or Session.evict() to detach the first object from the session before you are trying to load it a second time.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.