-->
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.  [ 6 posts ] 
Author Message
 Post subject: Behaviour on Reading and Updating and object from 2 tx
PostPosted: Fri Apr 23, 2004 3:54 am 
Newbie

Joined: Wed Feb 04, 2004 1:57 pm
Posts: 7
Hello

I use hibernate 2.1.2 version with IBM DB2 v7.2

Supose 1 object:
Object
field1 with "NONE"
field2 with "NONE"

Supose 2 transactions: (in disctinct threads)

tx1:open transaction1 with a new session
tx1:Read object with id 1
tx1:set object.field1 with "TXT1"
tx1:save object
tx2:open transaction2 with a new session
tx2:Read object with id 1
tx2:set object.field2 with "TXT2"
tx2:save object
tx1:commit transaction 1
tx2:commit transaction 2

what i get is the object 1 with field = "NONE" and field2= "TXT2".

Seems that saving and object is an atomic operation. Is it correct?

what i was especting for that situation is object 1 with field1="TXT1" and field2 with "TXT2".
It possible to do hibernate work like this?


Thank you for your patience.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 23, 2004 3:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
dynamic-update="true"


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 23, 2004 4:11 am 
Regular
Regular

Joined: Wed Mar 03, 2004 9:38 am
Posts: 70
You could also use versioning, see http://www.hibernate.org/hib_docs/reference/html/transactions.html#transactions-s3

When using versioning, committing tx2 in your example would fail.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 23, 2004 4:13 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
if his second tx fails, he will not have field2 with "TXT2"...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 23, 2004 4:43 am 
Regular
Regular

Joined: Wed Mar 03, 2004 9:38 am
Posts: 70
delpouve wrote:
if his second tx fails, he will not have field2 with "TXT2"...


Yes, that was my point. In some cases it might be useful to now the state of the entire object. Say, if the logic for setting field2 is something like:

Code:
if (field1 == "NONE") {
    field2 = "TXT2"
} else if (field1 == "TXT1") {
    field2 = "TXT3"
}


Of course, if field2 is totally unrelated to the state of the rest of the object and locking is not needed, using dynamic-update would be a better solution.


Top
 Profile  
 
 Post subject: dynamic-update=true satisfies my necesity
PostPosted: Fri Apr 23, 2004 4:56 am 
Newbie

Joined: Wed Feb 04, 2004 1:57 pm
Posts: 7
Hello,

dynamic-update=true satisfies my necessities

Thank you for your responses


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