-->
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.  [ 2 posts ] 
Author Message
 Post subject: Overwrite stale data
PostPosted: Wed May 05, 2004 10:03 am 
Newbie

Joined: Wed May 05, 2004 9:48 am
Posts: 8
Hi,

I have folowing problem. I have client A and B. Both fetches same row. A changes something and save it. B change something and save it. It gets exception about stale data. Since here OK.
Now I want to show user his data and data in DB. User then can choose to overwrite with his data or to leave the current state in DB. I want ask if I am doing it in right way.


Here is he part when overwriting the data with user's B (overwriting changes of user A).:

private overwritePerson(PersonData personData)
{
sess = HibernateUtil.currentSession(); //return the same session as used for reading, only reconnect it.

Transaction tx = sess.beginTransaction();

Person person = loadObjectPersonByPK(new Long(personData.getId()); //loads the person already associated with the session before - so no direct access to DB only to local cache

sess.refresh(person); //refreshing with current data from DB - so getting the data that user A changes
per.setData(personData); //set datas from user B

sess.saveOrUpdate(per); //save them
sess.flush();
tx.commit();
sess.close();
}

Is that refresh ok ? Or is there other way to tell hibernate to save some object and bypass the version check ? Or is is better to load second person using new session ?


Thanks for tips.

Here is mapping file:
<hibernate-mapping>

<class name="hibernate.test.Person"
table="person"
dynamic-update="true"
optimistic-lock="all"
>

<id name="id" type="long" unsaved-value="null" >
<generator class="sequence">
<param name="sequence">person_sequence</param>
</generator>
</id>

<version name="version"
type="long"/>

<property name="name"/>
<property name="surname"/>
</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 05, 2004 12:20 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
this apporach is not consistent since an other update may have been done between you comparison and your actual overwriting.

_________________
Emmanuel


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