-->
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.  [ 6 posts ] 
Author Message
 Post subject: manual optimistic locking with hibernate updating version
PostPosted: Mon Oct 17, 2005 1:23 pm 
Newbie

Joined: Fri Sep 17, 2004 8:27 am
Posts: 7
Hibernate version: 2.1.7

hi,

i'm trying to implement an optimistic locking with the following characteristics:
1. i'm using version columns
2. only the application should check for version conflicts
3. hibernate should update the version columns when updates occur, but not check for conflicts.

i know how to tell hibernate that i'm using a version column.
i know how to make the application check the version.
but how do i achieve the behaviour described above under 3.

thanks
martin


Top
 Profile  
 
 Post subject: Re: manual optimistic locking with hibernate updating versio
PostPosted: Mon Oct 17, 2005 2:45 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
schissler wrote:
Hibernate version: 2.1.7

hi,

i'm trying to implement an optimistic locking with the following characteristics:
1. i'm using version columns
2. only the application should check for version conflicts
3. hibernate should update the version columns when updates occur, but not check for conflicts.

i know how to tell hibernate that i'm using a version column.
i know how to make the application check the version.
but how do i achieve the behaviour described above under 3.

thanks
martin


Why would you want the application to check the version and not Hibernate ? That would leave the application vulnerable to overwriting of updates since it would be possible for one process to update the data after your version-check but before the database update is comitted.

That's why the method of appending the "and version_attribute = ?" to the update or delete statement is used.

If you really do want Hibernate to not check for conflicts, then don't use a <version> attribute and you can do it all yourself. (Not that I think this makes much sense)

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject: Re: manual optimistic locking with hibernate updating versio
PostPosted: Mon Oct 17, 2005 2:50 pm 
Beginner
Beginner

Joined: Wed Mar 16, 2005 4:07 pm
Posts: 22
i agree with the previous reader that it doesn't make much sense to let the application do the version checking. however if you really want it, i think you can write an interceptor and manipulate the version number in the onSave method.

schissler wrote:
Hibernate version: 2.1.7

hi,

i'm trying to implement an optimistic locking with the following characteristics:
1. i'm using version columns
2. only the application should check for version conflicts
3. hibernate should update the version columns when updates occur, but not check for conflicts.

i know how to tell hibernate that i'm using a version column.
i know how to make the application check the version.
but how do i achieve the behaviour described above under 3.

thanks
martin


Top
 Profile  
 
 Post subject: Re: manual optimistic locking with hibernate updating versio
PostPosted: Mon Oct 17, 2005 3:30 pm 
Newbie

Joined: Fri Sep 17, 2004 8:27 am
Posts: 7
hi pksiv,

thanks for the fast answer.

pksiv wrote:
Why would you want the application to check the version and not Hibernate ?


as i understand it hibernate checks for version conflicts on flush-time,
when he is doing the actual updates (by adding a version attribute in the where clause). if the check fails hibernate delivers a staleobjectexception.

the problem wih this behaviour is that hibernate stops with checking after the first conflict it has found. but i need infos (class and object-id) about all stale objects that are flushed at the end of my application transaction. i want to deliver these infos to my clients in order to give them the opportunity to react, e. g. merge.

pksiv wrote:
That would leave the application vulnerable to overwriting of updates since it would be possible for one process to update the data after your version-check but before the database update is comitted.


this is no problem as i can read the current version with select-for-update before checking it.

pksiv wrote:
if you really do want Hibernate to not check for conflicts, then don't use a <version> attribute and you can do it all yourself. (Not that I think this makes much sense)


that's what i expected.
but this chapter
http://www.hibernate.org/hib_docs/v3/re ... tic-manual
definitely gave me the impression that the behaviour i described above can be realized with hibernate. the documentation is a little confusing at that point.

again thanks.

bye
martin


Top
 Profile  
 
 Post subject: Re: manual optimistic locking with hibernate updating versio
PostPosted: Mon Oct 17, 2005 3:33 pm 
Newbie

Joined: Fri Sep 17, 2004 8:27 am
Posts: 7
hi weigingh,

weiqingh wrote:
however if you really want it, i think you can write an interceptor and manipulate the version number in the onSave method.


thanks for that point.
i do not know anything about interecptors, but this will change soon.
i can imagine that is is probably an elegant way for implementing a version update by application.

bye
martin


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 6:41 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
Here is a thread on these and other issues. There are many threads wondering how to recover from Hibernate-detected version conflicts. I'm trying to centralize discussion there.


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