-->
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.  [ 1 post ] 
Author Message
 Post subject: Concurrency handling with locking mechanism?
PostPosted: Fri Sep 02, 2011 2:59 am 
Newbie

Joined: Fri Sep 02, 2011 2:27 am
Posts: 1
Hi!

I am developing an application (deployed on JBoss 5.1.0.GA) containing a method where a single entity is picked from a collection selected from the database.
Concurrent access for this method should be possible and handled like "take the first entity and mark it as reserved, if it is still reserved by another process just pick the next entity and so on".
My solution for this is to iterate over the entities of the collection and write-lock the entities in a nested transaction until the lock invocation returns without a lock-exception. The nested transaction is neccessary because Hibernate sets the Transaction to rollback only if the lock fails.

The Problem is that we use JPA/JTA that doesn't support nested transactions. So I tried to implement a DataSourceTransactionManager with aspect orientated spring-aop for the method that locks the entity to handle it with JDBC, but I don't have access to the parent transaction/database-connection there. So the entitymanager still works on the parent transaction and set it to rollback-only when the lock fails.
To avoid the exception handling of Hibernate I tried to do the locking and exception handling in a stored procedure, but calling stored procedures is not supported for JPA.

So what is the common solution for this kind of concurrency handling?

I also thought about extending the hibernate implementation and overriding the lock method in order zu change the exception handling. Is that possible?

Thanks in advice,
Chistian


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.