0

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?

Beryllium
  • 12,808
  • 10
  • 56
  • 86
boris_dev
  • 232
  • 3
  • 12
  • Where does the `entityManager` come from? Please show your `persistence.xml`. Please add the complete source of `processWithLock`. – Beryllium Sep 13 '13 at 21:10
  • Unrelated comment, but ... All these annotations. All this presumed reflection going on. I'm just starting with JPA, but ... the performance tax for managing data this way seems like it should be sooooooo high. – scottb Sep 13 '13 at 21:36
  • @Beryllium thank you for editing my post, I added persistance.xml without entities. – boris_dev Sep 16 '13 at 11:10

1 Answers1

1

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.

Gerhard
  • 285
  • 3
  • 12
  • thank you for answer, should I put REQUIRES_NEW annotation if I want processWithLock to release the lock? – boris_dev Sep 16 '13 at 11:00
  • `REQUIRES_NEW` would execute the annotated method in a new, separate transaction. So yes, the lock would be released when the method returns. But the transaction of your MDB and the EJB are then independent of each other (one can fail and roll back and the other succeed or vice versa). Maybe that's ok in your case. – Gerhard Sep 16 '13 at 11:34