-->
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.  [ 10 posts ] 
Author Message
 Post subject: Patterns for working with StaleObjectStateException
PostPosted: Wed Feb 08, 2006 4:44 am 
Newbie

Joined: Wed Jan 04, 2006 9:13 am
Posts: 10
Location: Ukraine, Odessa
Anybody know any patterns (better if implemented patterns) for working with StaleObjectStateException?

Look at this two questions, witch can explain need of this patterns:

1
If we need save set of entities in second session and one or more of this entity are stale, how we can more powerful check versions and demarcate conflicts?
Each entity - (vertex of complex graph of objects) or (simple objects)

2
How we can implement merge?
replicate() or setVersion() or another?

If any know more questions, plz post this questions.

Thnks All.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 10:12 am 
Newbie

Joined: Wed Jan 04, 2006 9:13 am
Posts: 10
Location: Ukraine, Odessa
...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 1:44 pm 
Regular
Regular

Joined: Fri Sep 09, 2005 11:35 am
Posts: 101
Quote:
If the Session throws an exception, the transaction must be rolled back and the session discarded. The internal state of the Session might not be consistent with the database after the exception occurs.


The above is from the session javadocs. So you should not at least try to commit the transaction.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 4:22 am 
Newbie

Joined: Wed Jan 04, 2006 9:13 am
Posts: 10
Location: Ukraine, Odessa
abg1979 wrote:
Quote:
If the Session throws an exception, the transaction must be rolled back and the session discarded. The internal state of the Session might not be consistent with the database after the exception occurs.


The above is from the session javadocs. So you should not at least try to commit the transaction.


Oh really?

This rule know all and i am too.

Are you read my question?


Top
 Profile  
 
 Post subject: Re: Patterns for working with StaleObjectStateException
PostPosted: Thu Feb 09, 2006 12:48 pm 
Regular
Regular

Joined: Fri Sep 09, 2005 11:35 am
Posts: 101
$h@ke wrote:
Anybody know any patterns (better if implemented patterns) for working with StaleObjectStateException?


May be I really did not undestand your question. Can you be a little more clear?


Top
 Profile  
 
 Post subject: Re: Patterns for working with StaleObjectStateException
PostPosted: Fri Feb 10, 2006 4:32 am 
Newbie

Joined: Wed Jan 04, 2006 9:13 am
Posts: 10
Location: Ukraine, Odessa
abg1979 wrote:
$h@ke wrote:
Anybody know any patterns (better if implemented patterns) for working with StaleObjectStateException?


May be I really did not undestand your question. Can you be a little more clear?


I try again describe my question.

Little note from "Hibernate In Action":

Quote:
Using this exception (StaleObjectStateException), we might show the user of the second application transaction an error message (“You have been working with stale data because another user modified it!”) and let the first commit win. Alternatively, we could catch the exception and show the second user a new screen, allowing the user to manually merge changes between the two versions.


I am interested second way (catch the exception).
But in this book (also in hibernate reference and forums) I not find any exapmles or implementations or at least any descriptions how I can do this.

I may use replication(obj, ReplicationMode.OVERWRITE) or setVersion() + merge()?
(also many other questions burn when i try implement this behavior)

Thnx.


Last edited by $h@ke on Fri Feb 10, 2006 12:35 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Patterns for working with StaleObjectStateException
PostPosted: Fri Feb 10, 2006 6:44 am 
Beginner
Beginner

Joined: Mon Dec 05, 2005 4:15 am
Posts: 36
Quote:

I may use replication(obj, ReplicationMode.OVERWRITE) or setVersion() + merge()?
(also many other questions burn when i try implement this behavior)

Thnx.



I think the manually setting of the Version can be dangerous, because an another user can in this time edit the same data and thus increment the Version, in this case you will try to save the object with the smaller version as the object stored by another user.


Top
 Profile  
 
 Post subject: Re: Patterns for working with StaleObjectStateException
PostPosted: Fri Feb 10, 2006 7:19 am 
Newbie

Joined: Wed Jan 04, 2006 9:13 am
Posts: 10
Location: Ukraine, Odessa
sw79 wrote:
Quote:

I may use replication(obj, ReplicationMode.OVERWRITE) or setVersion() + merge()?
(also many other questions burn when i try implement this behavior)

Thnx.



I think the manually setting of the Version can be dangerous, because an another user can in this time edit the same data and thus increment the Version, in this case you will try to save the object with the same version as the object stored by another user.


Probably I or You do not understand the question correctly.
:)

Look at this code example, which written by me.


Customer dbObj = (Customer) session.get(Customer.class, myObj.getId());
myObj.setVersion(dbObj.getVersion());
session.merge(myObj);


where
dbObj - object version in DB, which has been saved while we thinking about changes on our object (во .а.ну. Ж))
myObj - our object with our changes

Realy we change only version of our object (not in DB), because we give version from DB and set this version for our object and than merge object.
Even if 3d (4d ...) user also change any property, our version can not be same, because we not edit(increment) version in DB (we tune our version to DB version ;)) and we will give StaleObjectExecption =-O.

So, how we can kill this recursion (ofcourse if first part of implementation completely good) ?

Rate/comment this idea plz.


Last edited by $h@ke on Mon Feb 13, 2006 4:29 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 8:08 am 
Beginner
Beginner

Joined: Mon Dec 05, 2005 4:15 am
Posts: 36
Ok now it is clear:)

I took a look on the default Hibernate implementation of the Replicator, it seems that it makes at the OVERWRITE mode the same as you try to make


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 8:38 am 
Newbie

Joined: Wed Jan 04, 2006 9:13 am
Posts: 10
Location: Ukraine, Odessa
sw79 wrote:
Ok now it is clear:)

I took a look on the default Hibernate implementation of the Replicator, it seems that it makes at the OVERWRITE mode the same as you try to make


Oh, really?

This is good surprise for me :).

I want summarize our talk.

From two approaches (replicate() and myObj.setVersion()) wich is better?

Replicate don't check version, therefore if more than 2 concurrently working users will provide changes to same object replicate() should occur inconsistent data (if 3d user alrady made changes no Exeption throw when we replicate())

Also replicate() update all other object graph points without version checking.

So, I am choice my pure implementation of replicate() (setVersion()).
Is this right way?
:)

Thnx.


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