-->
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: How to use optimistic-lock property for collection
PostPosted: Thu Jul 28, 2005 7:45 am 
Newbie

Joined: Tue Jun 21, 2005 1:03 am
Posts: 5
I have parent-child relation at java level

and in hibernate mapping i have


<class
name="Parent"
table="Parent"
select-before-update="true"
discriminator-value="not null"
dynamic-update="true"
dynamic-insert="true"
lazy="false"
>

<id
name="id"
column="P_ID"
type="long"
unsaved-value="null"
>
<generator class="native">
</generator>

</id>
<discriminator
column="P_TYPE"
type="int">
</discriminator>

<version
name="version"
type="int"
column="OBJECT_VERSION"
access="property"
unsaved-value="null"
/>
....
....

<subclass
name="P1"
discriminator-value="1"
select-before-update="true"
dynamic-insert="true"
dynamic-update="true"
>
<set name="children" inverse="true" sort="natural" lazy="false" cascade="all-delete-orphan" >
<key column="P_C_ID" not-null="true"/>
<one-to-many class="Child"/>
</set>
</sub-class>
</class>

<class
name="Child"
table="Chidren"
dynamic-update="true"
dynamic-insert="true"
select-before-update="true"
lazy="false"
>
<id
name="id"
column="C_ID"
type="long"
unsaved-value="null"
>
<generator class="native">
</generator>

</id>

<version
name="version"
type="int"
column="OBJECT_VERSION"
access="property"
unsaved-value="null"
/>
....
....

<many-to-one
name="timeUnit"
column="TP_TU_ID"
class="Parent"
/>
</class>

here i am considering multiuser scenario where 2 users are accessing same Parent object .. one want to update parent's properties and one want to update on of the property of any child.

requirement here is both users should succseed without any stale object exception.

I am using HibernateTemplate provided by Spring framework and
getHibernateTemplate.saveOrUpdate(Parent) to save any change in parent or childern.

I am getting staleObject Exception at last update(whichever happens at the last to update changes in parent or to update changes in child it doesn't matter).

In this scenario will optimistic-lock help?

how to apply optimistic lock and how ..?
what i read about optimistic locking is , we can allow concurrent modifications and can be specified at class level as optimistic-lock="dirty" and and property level as optimistic-lock="false".

can someone tell me how to use that optimistic locking with Hibernate template of Spring? and how i can achive my requirements with Hibernate.


Top
 Profile  
 
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.