-->
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.  [ 4 posts ] 
Author Message
 Post subject: Optimistic locking with EJBs & container-managed transac
PostPosted: Wed May 05, 2004 5:58 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
Our application is using the basic "session bean facade - thread local session - Hibernate-driven domain layer" model. All is basicall well.

One of the key layers of our system is a distributed job handling framework, where all state relating to concurrent jobs lives in the database, and where jobs are farmed out to multiple machines with JMS. We are trying to arrange the scheduling logic so it is truly distributed (i.e. no centralized scheduler, coordination done via the database).

The basic scheduling operation is "do some more work on the oldest existing job." It is possible that multiple machines may try to do more work concurrently, in which case they may wind up updating the same job records. In other words, locking issues are lurking. We are still early in development so we have not seen them yet, but I know they are in there.

Pessimistic locking could lead to various kinds of deadlocks, though I have hopes that selective LockMode.UPGRADE requests will help with that. But let's say pessimistic locking turns out to be too slow or too fragile and we want to go with optimistic locking.

Now come my questions.

- When using optimistic versioning, if we get a StaleObjectStateException, this means that we need to discard the whole session, right?

- When using ThreadLocalSession, if we discard the whole session, we may perhaps have to discard all work being done in the bean invocation, right?

- In other words, is it true that using container-managed transactions together with optimistic versioning generally requires a version mismatch to roll back the entire bean operation?

I know these questions are probably addressed in the Hibernate book, but I'm signed up for the Manning EAP already; what more do you want from me?! ;-)

Cheers!
Rob


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 5:53 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Yes to all of your questions except if you open a new session somewhere

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 12:32 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
But if you open a new session, it'll get associated with the same transaction, correct? In other words, with default "Required" transaction attribute on a bean, you get only one container-managed transaction per bean method invocation... so if you get a StaleObjectState exception in your Session, the only way to roll back the work (that you now don't want to commit because it is stale) is to roll back the entire method invocation. So how can you open a new session if you're rolling back the entire transaction that the container has opened for you?

Cheers,
Rob


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 07, 2004 3:04 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
CAll a new EJB in requiresNew.
But you're basically right and I usually avoid recover of session failure.

_________________
Emmanuel


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