Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-356

@PersistenceContext not injected in target bean when bean is intercepted

    XMLWordPrintable

Details

    Description

      Say you have this bean :

      @MyInterceptorBinding
      public class MyServiceBean implements MyService {

      @PersistenceContext
      protected EntityManager entityManager;

      @Inject @Any
      private Event<MyEvent> myEvent;

      public Object persist(Object obj)

      { entityManager.persist(obj); myEvent.fire(new MyEvent()); return obj; }

      }

      Where @MyInterceptorBinding is a simple interceptor binding with a trivial interceptor implementation :

      @MyInterceptorBinding @Interceptor
      public class MyInterceptor {

      @AroundInvoke
      public Object doInvoke(InvocationContext context) {
      Object result = null;

      try

      { return context.proceed(); }

      catch (Exception e)

      { throw new RuntimeException("error", e); }

      }

      The MyEvent field of the bean is correctly injected, but the entityManager is null.
      Note that if injecting @PersistenceContext EntityManager entityManager in the interceptor works fine.

      When the bean is not intercepted, its entityManager field is correctly injected.

      Attachments

        Issue Links

          Activity

            People

              marius.bogoevici Marius Bogoevici (Inactive)
              wdrai DRAI William (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: