object locking of entity bean instance in a SSBean[Environment: WebLogic 10.0, EJB3.0, Kodo/OpenJPA]
posted 7 years ago
I am facing bottle neck with Object Locking for an Entity bean using OpenJPA Persistence Manager under Weblogic 10.0 application server deployments.
I want to block [ for the specific method ] entity bean being accessed from other client programs when they invoke common method in a Stateless Session EJB. Particularly, Consider the situation:
Client1: Modifying Customer entity with id: 100. Then I locked that entity using OpenJPA Entity Manager within the transaction block. And i entered that thread to sleep before committing the transaction.
At this time, started new thread, Client2: Modifying the same Customer entity with id:100. I expected this thread will be get blocked when control pass to the lock() method. But it doesn't happened. It goes through the line of codes and also put into sleep.
After thread sleep timeout, first thread Client1 commit successfully. But the second gets Rollback Exception due to optimistic lock exception occurring since customer entity is modified in another transaction.
This exception is occurred because of Database level concurrency control for optimistic locking in a weblogic server. Its default to weblogic.
But, what i expected is to assert lock at the object level, thereby the 2nd thread - Client2 will be blocked while Client1 is in the middle of a transaction and then Client2 use modified Customer entity . But it doesn't happened. I used Kodo Persistance Provider as Persistence Unit, OpenJPAEntityManager to do transaction, locking , finding and merging the entity bean.
Can anyone provide help to fine grain this object locking functionality ??? I look forward to your brilliant thoughts......