[
https://issues.jboss.org/browse/AS7-2968?page=com.atlassian.jira.plugin.s...
]
Scott Marlow commented on AS7-2968:
-----------------------------------
When the test (EntityListenersTestCase) calls cmt.updateEmployee(emp) to update the
entity, as we prepare for the stateful bean call, StatefulComponentInstanceInterceptor
sets ComponentInstance.class in context private data.
When the cmt.updateEmployee() returns, we return up the stack to the
StatefulComponentInstanceInterceptor, which clears ComponentInstance.class in context
private data.
Later up the stack, the TX interceptor commits the transaction. This properly triggers the
database update, however when the user code, calls indirectly to CurrentInvocationContext,
the context has no private data for ComponentInstance.class. So, we throw
currentComponentNotAEjb(component).
I think that the proper fix, is having StatefulComponentInstanceInterceptor, handoff the
clearing of the ComponentInstance.class in context private data to happen after the tx
ends. Maybe we could hand that off to happen at the end of
CMTTxInterceptor.processInvocation().
Is that possible?
@PreUpdate entity callback not running in caller's context when
Container Managed Transactions are used
-------------------------------------------------------------------------------------------------------
Key: AS7-2968
URL:
https://issues.jboss.org/browse/AS7-2968
Project: Application Server 7
Issue Type: Bug
Components: EJB, JPA / Hibernate
Affects Versions: 7.1.0.Beta1
Reporter: jw
Assignee: Scott Marlow
Fix For: 7.1.0.CR1
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.
{noformat}
@Entity
@EntityListeners({ MyListener.class })
public class MyEntity {
...
}
{noformat}
{noformat}
public class MyListener {
@PreUpdate
@PrePersist
public void onEntityCallback(Object entity) {
EJBContext ctx;
ctx = createInitialContext().lookup("java:comp/EJBContext");
System.out.println(ctx.getCallerPrincipal().getName());
}
}
{noformat}
{noformat}
@Stateless
public class MyServiceBean implements MyServiceRemote {
@Override
public void updateEntity(MyEntity entity) {
entityManager.merge(entity);
}
}
{noformat}
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
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see:
http://www.atlassian.com/software/jira