2 Replies Latest reply on Jan 13, 2010 10:26 AM by thomasgo

    Override EJB annotation in EAR

    thomasgo

      Hi, I have a question regarding the override of EJB 3.0 annotations on a per EAR basis.


      I know that I can override settings like JNDI name or injection parameters using the ejb-jar.xml.

      However, this file has to be located in the jar that contains the annotated services. Is this correct?

       

      Please consider the following (simplified) setup:

       

      A file service.jar that contains:

      - a DAO service (SSB) with an annotated entity manager:

            @PersistenceContext(unitName="someUnit") private EntityManager em;

       

      - a business service (SSB) with annotated @EJB and/or @Resource annotations

       

       

      Two EARs which both include service.jar.

      However, both EARs define different persistence units that should be injected into the DAO service.

      I don't want to recompile the jar for every new EAR that is built, so the override data must be located outside the jar.


      Ist this possible somehow?

       

      Thanks for your answers.

       

      Best regards,

       

      Thomas

        • 1. Re: Override EJB annotation in EAR
          wolfc
          Would defining the persistence unit on EAR level help out?
          • 2. Re: Override EJB annotation in EAR
            thomasgo

            Well, we already define the persistence units in a separate persistence.xml, i.e.

             

            EAR

            - persistence.jar

            -- persistence.xml -> references the entity jar's via <jar-file>

            - dao-service.jar

            -- daoService -> entity manager ref

             

            The problem is that our jar files represent components that might be reused in different applications.

            However, each application might define different persistence units that the components should reside in.

             


            I could set a different persistence unit per component jar but then I'd have many units in persistence.xml.

            Additionally, I'm not sure that if each unit references only a subset of the entities, queries like "select A.b from A" would work in cases where A is in PU "A" and B or A.b is registered in PU "B". Plus registering A and B in both units doesn't seem that good (which unit is the owner? are the instances shared? etc.)