-->
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.  [ 7 posts ] 
Author Message
 Post subject: Concurrency problems with optimistic locking
PostPosted: Fri Oct 17, 2003 2:28 pm 
Newbie

Joined: Fri Oct 17, 2003 12:40 pm
Posts: 16
I problem with concurrency (optimistic locking). When userA deletes the record and userB updates it, I get an error. My problem is when userA updates the record and userB updates the record later, userB overrides the change made by userA. But I should get a StaleObjectError when userB updates the record.
I am using the technique mentioned in the reference document 14.3.2 (Many sessions with automatic versioning). I do use saveOrUpdate, then flush, commit and close. Is there any additional steps or am I doing anything wrong.

Thanks for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 17, 2003 3:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
How are you implementing optimistic locking? Include your mapping file.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 17, 2003 4:33 pm 
Newbie

Joined: Fri Oct 17, 2003 12:40 pm
Posts: 16
I think not. What should I add in the mapping file to implement optimistic locking. Thanks


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="TestClass" table="table1">
<id name="Id" column="Primay_ID" type="long" unsaved-value="-1">
<generator class="sequence">
<param name="sequence">SEQUENCE_ID</param>
</generator>
</id>
<property name="Name" column="NAME" type="string"/>
<property name="Comments" column="COMMENTS" type="string"/>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 17, 2003 4:40 pm 
Newbie

Joined: Fri Oct 17, 2003 12:40 pm
Posts: 16
user100 wrote:
What should I add in the mapping file to implement optimistic locking. I am trying to implement optimistic locking using "Many Sessions with automatic versioning (14.3.2 in the reference doc). Thanks for your help.


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="TestClass" table="table1">
<id name="Id" column="Primay_ID" type="long" unsaved-value="-1">
<generator class="sequence">
<param name="sequence">SEQUENCE_ID</param>
</generator>
</id>
<property name="Name" column="NAME" type="string"/>
<property name="Comments" column="COMMENTS" type="string"/>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 17, 2003 5:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Depends on what type of strategy you want to use. Check out the docos:
http://www.hibernate.org/hib_docs/reference/html/transactions.html#transactions-s3


Last edited by steve on Fri Oct 17, 2003 5:11 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 17, 2003 5:05 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
user100 wrote:
I think not. What should I add in the mapping file to implement optimistic locking. Thanks


Add a version column to your table, and add this
Code:
<class...>
...
<version
        column="version_column"   
        name="version"       
        type="integer"           
/>
</class>


Read 4.1.7 section of the ref guide

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 17, 2003 9:41 pm 
Regular
Regular

Joined: Fri Sep 05, 2003 12:01 am
Posts: 80
Location: Bogot
You might also wanna check this out in case you encounter a dirty read or conflict:

http://hibernate.bluemars.net/hib_docs/api/net/sf/hibernate/StaleObjectStateException.html

_________________
Mauricio Hern


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