-
Bug
-
Resolution: Done
-
Major
-
7.1.0.Beta1
-
None
If an Entity Bean has a @PreUpdate listener, the listener is not called in the context of the caller (session bean) in case of Container Managed Transactions.
As a result, an jndi lookup in the callback for 'java:comp/EJBContext' returns always null. The @PreUpdate callback should run in the context of the caller.
@Entity
@EntityListeners({ MyListener.class })
public class MyEntity {
...
}
public class MyListener {
@PreUpdate
@PrePersist
public void onEntityCallback(Object entity) {
EJBContext ctx;
ctx = createInitialContext().lookup("java:comp/EJBContext");
System.out.println(ctx.getCallerPrincipal().getName());
}
}
@Stateless
public class MyServiceBean implements MyServiceRemote {
@Override
public void updateEntity(MyEntity entity) {
entityManager.merge(entity);
}
}
This listener works fine on @PrePersist (Container- and Bean Managed Transactions) but fails on @PreUpdate with a NullPointerException if container managed transactions are used.
Workaround: use User Transactions instead of Container Managed Transactions