omar al kababji created WFLY-3473:
-------------------------------------
Summary: JPA entity listener fails to lookup EJBContext when using client
transactions
Key: WFLY-3473
URL:
https://issues.jboss.org/browse/WFLY-3473
Project: WildFly
Issue Type: Bug
Security Level: Public (Everyone can see)
Components: CDI / Weld, EJB, JPA / Hibernate
Affects Versions: 8.1.0.Final
Reporter: omar al kababji
Assignee: Stuart Douglas
I have created a new EAR project in eclipse with an ejb module and a web module, in the
ejb module I created a Stateless session bean (EjbBean1) and a JPA entity listener
(JPAListener) with a method @PreUpdate annotated method that lookups an EJBContext from
JNDI as follows:
@PreUpdate
public void preUpdate(Object obj) throws Exception {
InitialContext ic = new InitialContext();
SessionContext ctx = (SessionContext) ic.lookup("java:comp/EJBContext");
Principal principal = ctx.getCallerPrincipal();
}
In the web module I have created a CDI bean (TestBean) that looksup the session bean
(EjbBean1) and executes a method that updates a JPA entity.
TestBean {
@EJB
private EjbBean1 ejbBean1;
}
Doing some tests I noticed the following:
1. If I execute the TestBean and define no transaction the entity is saved correctly and
the entity listener looks-up the EJBContext. (OK)
2. If I execute the TestBean with a locally initiated user transaction (looked up using
(java:comp/UserTransaction) the entity listener fails to look-up the EJBContext and I get
a NamingException saying that the EJBContext is not bound (Bug? I expected to get the
EJBContext as in point 1)
3. If I execute the TestBean with a locally initiated transaction (looked up using
java:comp/UserTransaction) and flush the entity manager in the session bean right before
it returns. The entity listener looks-up the EJBContext correctly. (OK) ... but why when I
flush the entity manager in EjbBean1 the error encountered in point 2 is not present any
more?
4. If I look-up remotely the session bean EjbBean1 from a java client (outside Wildfly)
the entity listener looks-up the EJBContext correctly. (OK)
My assumption (may be completely wrong) is that when I initiate a local user transaction
in TestBean, the entity manager is flushed in the web module (once the transaction is
committed) instead of the ejb module, and in the web module it is failing to load the
EJBContext, but both the web and ejb are part of the same EAR!
Here is the application.xml descriptor:
<application
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd" id="Application_ID"
version="7">
<application-name>myear</application-name>
<display-name>myear</display-name>
<module>
<ejb>my-ejb.jar</ejb>
</module>
<module>
<web>
<web-uri>my-web.war</web-uri>
<context-root>my-web</context-root>
</web>
</module>
</application>
--
This message was sent by Atlassian JIRA
(v6.2.3#6260)