-->
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.  [ 2 posts ] 
Author Message
 Post subject: Optimistic lock on delete
PostPosted: Tue Mar 23, 2004 11:10 am 
Beginner
Beginner

Joined: Tue Sep 30, 2003 10:09 am
Posts: 34
Location: London, UK
Is there a way to get Hibernate to do optimistic locking on delete operations?

I've got optimistic locks on update, that's fine. I'd also like a delete operation to fail if the object being deleted has been updated since it was retrieved.

Or to put it another way: two threads T1 and T2 both read an Object O (at version 1). T1 does an update to O, incrementing its version to 2. T2 then deletes its O (the version 1 one) but this should then fail because version 1 no longer exists.

Is this one of those things that isn't considered useful/normal, or have I missed a switch or an XML attribute somewhere?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 24, 2004 6:35 am 
Beginner
Beginner

Joined: Tue Sep 30, 2003 10:09 am
Posts: 34
Location: London, UK
OK, no takers so far. So how about I suggest a possible solution?

I'm thinking that instead of calling Session.delete(Object object) I could instead call Session.delete(String query) with a query of something like:

Code:
FROM employee WHERE employee.id = ? AND employee.version = ?


I can then check the return value of delete(String query) and throw an exception to indicate that the underlying object has been changed if no rows were deleted.

Clearly an update-related optimistic lock using versioning could be done in exactly the same way, but Hibernate provides a facility to hide the version check away, and I'm just wondering if there's a similar facility for delete-related optimistic locks.


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