-->
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.  [ 3 posts ] 
Author Message
 Post subject: Transaction Concurrency
PostPosted: Mon Apr 03, 2006 3:39 pm 
Newbie

Joined: Mon Apr 03, 2006 3:03 pm
Posts: 2
Hibernate Version: 2.1.4

I hope I no one will be offended if I ask a general question. We have encountered a highly repeatable situation and I could use a little education as to how to best avoid it.

Imagine, if you will, two threads with identical activities and overlapping transactions:

1) Session a/Transaction a begin and load an Object X.
2) Session b/Transaction b begin and load the same Object.

3) Session a deletes Object X and Transaction A commits.
4) Session b deletes Object X and Transaction B commits. And...

An exception will occur because Session b cannot find the row.

(The text of the message will vary depending on whether batch updates are enabled but the indication is the same = Unexpected row count.)

Obviously the delete could first confirm the presence of the row but is there a better way?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 4:06 pm 
Regular
Regular

Joined: Tue Mar 07, 2006 11:18 am
Posts: 54
Location: Berlin
Have you heard about Isolation levels on you database?
Your transaction will currently run on "read commited" which is the default isolation afaik.

I would suggest that you let the database do the job for your problem.

You can find the something about that here:
http://www.hibernate.org/hib_docs/reference/en/html_single/#transactions-locking


a good description about isolation level (this is basicly database independend:
http://www.mssqlcity.com/Articles/General/TIL.htm

simon


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 4:12 pm 
Newbie

Joined: Mon Apr 03, 2006 3:03 pm
Posts: 2
Thanks Simon.

Wasn't aware that you could set the concurrency on a Txn by Txn basis...


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