4 Replies Latest reply on Jul 16, 2011 4:51 AM by Viraj Perera

    Conflict between persistence units.

    Viraj Perera Newbie

      Hi All,

       

      The summary of my problem as follows.

       

      App server: JBoss 5.1

       

      I have 2 applications (packaged as ear) and each has their own persistence unit. Each application has a same set of SLSB to provide common functionalities, such as loading users, loading menus. Package name of those beans are same. For example  "com.auth.AccessControlEAO" bean is in both applications. In the application 1, it has a reference to the APP1-PU. In the application 2, it has a reference to the APP2-PU.

       

      In application 1 ear file:

      app1.ejb.jar

           |

           |--META-INF -- persistence unit (name='APP1-PU')

           |---com.auth.AccessControlEAO @Stateless(name = "AccessControl") (has a reference to the APP1-PU)

       


      In application 2 ear file:

      app2.ejb.jar

           |

           |--META-INF -- persistence unit (name='APP2-PU')

           |---com.auth.AccessControlEAO @Stateless(name = "AccessControl") (has a reference to the APP2-PU)

       

       

      ERROR 1: When I deploy application-1.ear it works fine. Then if I do a hot deployment of application2.ear, application 2 works fine. But the application 1 crashes.

       

      ERROR 2: If I stopped the server and deploy both applications and then restart the server, application1 get deployed correctly. But then the application2 complains about missing persistence unit and according to the error trance it tries to find the 'APP1-PU' and then got failed to deploy.

       

      This is the main error in the error trace.

      ...

      java.lang.IllegalArgumentException: Container jboss.j2ee:ear=application2.ear,jar=application2-ejb.jar,name=AccessControl,service=EJB3 failed to resolve persistence unit APP1-PU

                at org.jboss.injection.PersistenceUnitHandler.addPUDependency(PersistenceUnitHandler.java:135)

                at org.jboss.injection.PersistenceContextHandler.loadXml(PersistenceContextHandler.java:76)

      ...

       

      I could overcome this error by renaming packages in each jar file, as follows.

       

      In application 1 ear file:

      app1.ejb.jar

           |

           |--META-INF -- persistence unit (name='APP1-PU')

           |---app1.com.auth.AccessControlEAO @Stateless(name = "AccessControl")

       


      In application 2 ear file:

      app2.ejb.jar

           |

           |--META-INF -- persistence unit (name='APP2-PU')

           |---app2.com.auth.AccessControlEAO @Stateless(name = "AccessControl")

       

       

       

      My question is that:

       

      ISN'T it possible to have SAME package name + class name for SLSBs, those has references to their relevant persistence units configured in each application as in the example?