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.  [ 1 post ] 
Author Message
 Post subject: Reattaching detached objects using lock() and update()
PostPosted: Sun Feb 26, 2006 8:41 pm 

Joined: Wed Jan 18, 2006 7:30 pm
Posts: 4
I am working on a web application. We use Spring for transaction management, have an OpenSessionInView filter and use optimistic locking with Hibernate versioning.

When a user edits a record we put the relevant object into the HTTP session and reattach it when they submit / save their changes. At this point we need access to some of the proxied objects and lazy loaded collections that were not initialised when the object was loaded, and also to do a version check.

Testing has shown that we can access proxied objects and do the version check by reattaching the detached object with lock(object, LockMode.READ) and specifying cascade="lock" on those relationships we want to access.

But this does not work for lazy loaded collections. To access them we also need to call update(object) and specify cascade="save-update" at all points along to path to the collection.

So for example I load a Timesheet and detach it. I reattach it to a new session, and want to access a collection on the Timesheet's owner (a Resource), to which the Timesheet is mapped with a many-to-one. To do this I need to specify cascade="update" on the many-to-one between Timesheet and Resource and on the Resource's collection.

This has the side-effect though that the version number of the Resource is incremented. As a Resource is used extensively throughout the system this scenario will repeat itself to the extent that many unrelated actions will try and increment it's version number, causing unnecessary lock failures. This would be inappropriate because it is not changing in these cases.

So firstly, is this expected behaviour of lock() and update()? Should I be able to access lazy loaded collections using just lock()?

Is there a way of supressing the versioning of the Resource?

Does anyone have any suggestions of any alternative approaches?

Many thanks everyone.

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

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.