Question

I work with WebSphere 7 and OpenJPA.

Here is two beans and part of persistance.xml:

<persistence-unit name="ASAP_Main">
    <jta-data-source>jdbc/ASAPDB</jta-data-source>
    <properties>
            <property name="openjpa.Optimistic" value="false"/>
            <property name="openjpa.ReadLockLevel" value="none"/>
            <property name="openjpa.WriteLockLevel" value="none"/>
            <property name="openjpa.LockManager" value="pessimistic(VersionCheckOnReadLock=false,VersionUpdateOnWriteLock=false)"/>
            <property name="openjpa.LockTimeout" value="20000"/>
    </properties>
</persistence-unit>
    @PersistenceContext(unitName = "ASAP_Main")
    private EntityManager em;

    @MessageDriven
    public class A implements MessageListener {
        @EJB
        private B b;

        @TransactionAttribute(TransactionAttributeType.REQUIRED)
        public void onMessage(Message message) {
            b.processWithLock(message.getObject());
        ...
        }
     }

    @Stateless
    public class B{
        @TransactionAttribute(TransactionAttributeType.REQUIRED)
        public void processWithLock(Object obj){
        em.lock(obj)
        ...
        }
    }

Does processWithLock release lock after execution?

Was it helpful?

Solution

Your MDB defines the transaction border, the EJB B just takes part in the transaction started by A. A nested transation is something different.

All database locks are held until the transaction commits or rolls back, which is when A.onMessage() returns. So processWithLock will not release the lock after execution, when called within a global transaction.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top