2 Replies Latest reply on Aug 13, 2013 3:46 AM by Alexander Hartner

    @PersistenceContext annotation in an abstract superclass

    Bruce Raggett Newbie

      Hello All,

      I know that the JBoss EJB3 implementation allows me to use the @PersistenceContext annotation in an abstract superclass.

      For example:

      public abstract class MyAbstractSuperclass implements MyInterface {

      @PersistenceContext()
      EntityManager entityManager;

      // Other code which I have omitted

      }

      Can anyone point me to EJB3 documentation which specifies that using the @PersistenceContext in an abstract superclass is valid according to the specification and will therefore be portable across application servers?

      Many thanks,
      Bruce.

        • 2. Re: @PersistenceContext annotation in an abstract superclass
          Alexander Hartner Expert

          I know this thread goes back quite a while. Yet I am facing the same issue. I have declared and inject a PersistenceContact in an abstract superclass, which is extended by serveral concrete MDBs and SLSBs. However when I deploy this I get the following error :

           

           


          ObjectName: jboss.j2ee:ear=ABCEJB.ear,jar=ABCEJB.jar,name=BatchJobListener,service=EJB3

          State: FAILED

          Reason: java.lang.RuntimeException: An exception occurred initialising interceptors for class com.abc.backend.

          jobs.BatchJobListener.init

          I Depend On:

          persistence.units:ear=ABCEJB.ear,jar=ABCEJB.jar,unitName=entityManager



          ObjectName: jboss.j2ee:ear=ABCEJB.ear,jar=ABCEJB.jar,name=BinListener,service=EJB3

          State: FAILED

          Reason: java.lang.RuntimeException: An exception occurred initialising interceptors for class com.thunderhead.backend.

          jobs.BinListener.init

          I Depend On:
          persistence.units:ear=ABCEJB.ear,jar=ABCEJB.jar,unitName=entityManager

           

           

          any ideas if this is supposed to work. I am aware of the work around to declare an abstract getter in the superclass, and then inject in the concrete subclasses and access the injected context via the getter. It would be nice to to be able to inherit the injected Persistence Context though, which as Bill suggests, seems to be possible.