[jboss-user] [EJB 3.0] - @PrePersist @PreUpdate within @AroundInvoke results in call-

gnulp do-not-reply at jboss.com
Tue Nov 28 15:26:03 EST 2006


I have a stateless sessionBean defined using an interceptor on a businessMethod as well as a entityBean with a listener.


  | @Stateless
  | @TransactionAttribute(TransactionAttributeType.REQUIRED)
  | public class MyStatelessSessionBean {
  |    ...
  |    @Interceptors(MyInteceptor.class)
  |    public Object myPersistMethod(MyEntityObject myEntity) {
  |         ... 
  |         // using an injected entityManager
  |         return entitymanger.merge(myEntity)
  |        ...
  |    }
  | }
  | 
  | public class MyInteceptor {
  |    @AroundInvoke
  |    public Object doInteception(InvocationContext context) throws Exception {
  |       try {
  |          System.out.println("before proceed");
  |          return context.proceed();
  |       } finally {
  |          System.out.println("after proceed");
  |       }
  |    }
  | 
  | @Entity
  | @EntityListeners(MyEntityListener.class)
  | public class MyEntity {
  |      ...
  |      // some attributes / setters an getters ...
  |      ...
  | }
  | 
  | public class MyEntityListener {
  |     @PrePersist
  |     public void prePersit(Object entity) {
  |         System.out.println("prePersist entity"); 
  |     }
  | 
  |     @PreUpdate
  |     public void preUpdate(Object entity) {
  |         System.out.println("preUpdate entity"); 
  |     }
  | }
  | 
  | 

calling the business-Method from a client twice with the same entity results in different call-stacks:


  | ======= CREATING THE ENTITY with myEntity = service.myPersistMethod(myEntity) ==============
  | INFO  [STDOUT]   before proceed
  | INFO  [STDOUT]   prePersist entity
  | INFO  [STDOUT]   after proceed
  | 
  | ...
  | 
  | ======= UPDATING THE ENTITY with myEntity = service.myPersistMethod(myEntity) ==============
  | INFO  [STDOUT]   before proceed
  | INFO  [STDOUT]   after proceed
  | INFO  [STDOUT]   preUpdate entity
  | 
  | 

the first output is as expected, but the second isn't what I was expecting, because there is now way for the interceptor to get some information about possible updates within the entity-callbacks ...

Is this behaviour anywhere defined ? Can I assume any calling order in combination of Interceptors and callbackhandlers within a transaction - or is it explicitly undefined ...

Thx for any help ---

wbr


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

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



More information about the jboss-user mailing list