Uploaded image for project: 'Application Server 7'
  1. Application Server 7
  2. AS7-2968

@PreUpdate entity callback not running in caller's context when Container Managed Transactions are used

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 7.1.0.CR1
    • 7.1.0.Beta1
    • EJB, JPA / Hibernate
    • None

    Description

      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

      Attachments

        Activity

          People

            jaikiran Jaikiran Pai (Inactive)
            jw_jira Juerg Weilenmann (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: