-->
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.  [ 5 posts ] 
Author Message
 Post subject: Check if other user changed object
PostPosted: Wed Oct 12, 2005 5:54 am 
Newbie

Joined: Fri May 27, 2005 6:16 am
Posts: 14
Hi,

I am using hibernate client-side for persistence, and it is working great. This is difficult for concurrency checks of course.
How can I check if an object that is in the local hibernate cache is still the latest version in the database. Is it even possible to check if an object that has been changed locally (but not saved yet) has not been changed in the database in the meantime?

Regards,
Leen Toelen


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 7:18 am 
Pro
Pro

Joined: Mon Jan 24, 2005 5:39 am
Posts: 216
Location: Germany
Hi,

you can try the refresh method in Session class.
For checking if your instance is already dirty I think
there was another thread some weeks ago.
Try searching for isDirty or something like that.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 8:24 am 
Newbie

Joined: Wed Oct 12, 2005 4:54 am
Posts: 9
In Hibernate there is a technique integrated called "Managed Versioning".
For this purpose you need to add to your mapping hbm.xml-files following line beneath the </id> tag:
Code:
<version name="hbversion" column="hbversion" />

Don't forget a column in your regarding table with that name.
You also need a deklaration in your mapping class
Code:
int hbversion;

..and of course a getter and setter method.


Everytime you update an entity, hibernate adds to the update statement someting as WHERE hbversion=2 (suggesting that 2 was the version when you read the entity).
After updating hibernate checks the returned 'effected-rows' value and if it's zero, then an exception will be thrown: StaleObjectStateException. With this Exception you get the information, that a different transaction already updates the entity.

I hope you get what I meant and I told it exactly ;)

best regards


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 9:23 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
I call hibernate lock with nowait option - if lock doesn't success then another user change object - this lock objects for another user , too

This work for databases with lock nowait option (oracle , postgresql ?)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 7:39 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
Here's another thread on this topic. Our strategy is to not actually change the versioned objects until the user clicks save. Then we lock the objects for upgrade, and check the versions. If they've changed, we flush and commit (releasing all locks), and ask the user what to do, then repeat.

Cheers!
Rob


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