[jboss-jira] [JBoss JIRA] (AS7-2968) @PreUpdate entity callback not running in caller's context when Container Managed Transactions are used

jaikiran pai (JIRA) jira-events at lists.jboss.org
Thu Jul 18 04:14:27 EDT 2013


    [ https://issues.jboss.org/browse/AS7-2968?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12790611#comment-12790611 ] 

jaikiran pai commented on AS7-2968:
-----------------------------------

We have testcase for this exact usecase and it's passing https://github.com/wildfly/wildfly/blob/master/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jpa/entitylistener/EntityListenersTestCase.java. The listener is here which does the java:comp/EJBContext lookup and uses it without any problem https://github.com/wildfly/wildfly/blob/master/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jpa/entitylistener/MyListener.java#L66.

If you have a simple application which reproduces this, then please attach it.

                
> @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: Juerg Weilenmann
>            Assignee: jaikiran pai
>             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
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the jboss-jira mailing list