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