[jboss-user] [EJB 3.0] - How do I lock an Entity bean?

Doug.Palmer do-not-reply at jboss.com
Wed Jul 19 19:00:32 EDT 2006


Hi

I am running EJB3 with JBoss 4.0.4 and I am trying to lock an Entity bean while I am accessing/updating it.  However, I don't seem to be able to lock the bean.  My system consists of:

A JMS queue; a MDB listening to the queue and an Entity bean for persistence.

The client places an update for an instance of the entity bean on the JMS queue.  A MDB removes the data; checks that the relevant instance of the entity bean is available; performs some processing on the data and persists the data in the entity bean.

The client may send multiple updates for the same instance of the entity bean but the processing must occur in isolation.  So the MDB needs to lock the Entity while it is processing and release it when it has persisted the data.

I have tried various combinations of the following but multiple MDB instances manage to access the same Entity instance:

1. Annotate MDB.onMessage() with @TransactionAttribute(TransactionAttributeType.REQUIRED).

2. Set the type of the EntityManagers @PersistentContext to PersistenceContextType.TRANSACTION.

3. Adding @ActivationConfigProperty(propertyName = "Transacted", propertyValue = "true"), @ActivationConfigProperty(propertyName = "Xa", propertyValue = "true") to the MDB's activation config.

4. Calling EntityManager.lock(Entity, LockModeType.READ).


Can anyone tell me how to pessimistically lock the Entity instance?  What have I missed?

Regards
Doug


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3959372#3959372

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3959372



More information about the jboss-user mailing list