-->
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.  [ 3 posts ] 
Author Message
 Post subject: Refresh does not cascade on detached objects
PostPosted: Fri Jun 06, 2008 4:45 am 
Newbie

Joined: Wed Jun 21, 2006 12:32 pm
Posts: 2
I have a problem with cascading of session.refresh() if the object to refresh is detached. (The cascade type is set to ALL). Only the object passed to refresh itself is refreshed but not any referenced objects.

My application tries to refresh the parent object if an optimistic locking exception occured in the previous request.

I debugged Hibernate and found that Hibernate actually loads the updated object from the database
but in a new instance that doesn't get copied on the object graph I actually tried to refresh.
As a workaround, I can refresh the child object manually by iterating over the children collection and invoking refresh on each child.

Is there something I am doing wrong?

Hibernate version:

3.2.3.ga, Also tested with 3.2.6


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 06, 2008 11:42 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
I think there may be a problem with this approach.

Why the need to refresh these objects. I might suggest you keep your session open a bit longer, and leverage the Open Session in View pattern.

The fact is, you're closing your session too early? Why commit the transaction if the data is still needed? Why close the session if you're not done with it. I think there are some real opportunities for optimization here if you keep your session open.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 06, 2008 12:01 pm 
Newbie

Joined: Wed Jun 21, 2006 12:32 pm
Posts: 2
Cameron McKenzie wrote:
I think there may be a problem with this approach.

Why the need to refresh these objects. I might suggest you keep your session open a bit longer, and leverage the Open Session in View pattern.

The fact is, you're closing your session too early? Why commit the transaction if the data is still needed? Why close the session if you're not done with it. I think there are some real opportunities for optimization here if you keep your session open.


I am actually using the Open Session in View pattern. But I am using refresh() for a different purpose.

In my scenario there was an optimistic locking error on the previous request which is displayed to the user. On the following page the object graph where the error occurred is loaded again from the database so the user can redo his changes based on the current database version.

To achieve this, the object is refreshed in the request and displayed again on a form.
In some way or other I have to get the current version of the object from the database. The other way would be to load the object completely from the database using Session.get(). But I thought, refresh was built to exactly serve this purpose.

I hope my usage of refresh is clearer now.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.