4 Replies Latest reply on May 8, 2009 3:47 AM by erili

    Annotating @persistencecontext from a different ear

      Hello!

      I'm trying to inject a persistencecontext in my ejb that is defined in another ear.

      Project setup:
      aaa.ear
      |-aaa-ejb.jar

      bbb.ear
      |-bbb-ejb.par.jar (defines the persistence unit)


      In aaa-ejb:

      // Needs to bind to:
      // persistence.units:ear=bbb.ear,jar=bbb-ejb.par.jar,unitName=MYPERSISTENCEUNIT
      // JBOSS BUG! (https://jira.jboss.org/jira/browse/EJBTHREE-1252)
      @PersistenceContext(unitName="XXXbbb-ejb.par.jar#MYPERSISTENCEUNIT")
      private EntityManager em;
      

      The above code is parsed to:
      persistence.units:jar=bbb-ejb.par.jar,unitName=MYPERSISTENCEUNIT
      

      I cannot figure out how to pass the correct EAR to the annotation. Any ideas?

        • 1. Re: Annotating @persistencecontext from a different ear

          Sorry, I forgot to add I'm using JBoss 4.2.2GA

          • 2. Re: Annotating @persistencecontext from a different ear
            jaikiran

            As far as i remember, the persistence units in different EARs are not accessible from the other EAR.

            • 3. Re: Annotating @persistencecontext from a different ear

              Ok.

              Then I'll have to figure out a different solution. The bbb-ear is a large application with slow release cycles. I'm developing a maintenance application (aaa.ear) that deploys as a stateless EJB that can pull entities from the main application and send data from them to a client through JMX. So the ejb in aaa.ear need to access some entities in bbb and it would be really nice if this could be done through the same persistence context that the main application is using.

              This would allow the maintenance guys to hot deploy the hook ear, run some batch jobs and whatnot and undeploy it without having to clutter the main application.

              I guess I could connect directly to the datasource, but then the cache would be bypassed and only reads would be possible.

              Am I trying to do something impossible? Are there any other approaches I should look into? I'm very new to JavaEE, I hope I'm not asking dumb questions.. Oh, the shame..! :-)

              • 4. Re: Annotating @persistencecontext from a different ear

                What I did to solve my problem was to get the product development team to add a new session bean in the main product that is injected with a entity manager and a getEntityManager method that the aaa.ear ejb can call.