Version 1

    Hi,

     

    I am using jboss 6 EAP and was facing issue in JPA w.r.t multiple persistence.xml files. My domain class (i.e. classes annotated with JPA annotations) reside under ejb.jar files which are packed/deployed as EAR file.

    Earlier I don't have single persistence.xml (i.e. each EJB compoents have their own persistence file with same persistence unit) and I was expecting that all persistence unit will be merged by server itself  while deploying ejbs but that was not a case.

    JBOSS server is reading all persistence.xml files but only first ejb jar file ( i.e. file name mentioned in application.xml) was loaded/configured by JPA which was causing the problem in our code. Now I read some blogs and found that "I need to create single persistence file located under META-INF folder of EAR and that should use '<jar-file> tag to list all JPA annotated files/jars". I did following changes in my code base

     

    1. Removal of persistence.xml file from every ejb.jar files

    2. new persistence.xml file in EAR's META-INF folder

    3. list all ejb.jar files in persistence.xml

     

    here is my EAR structure

     

    MyApp.ear

    -META-INF

      -- application.xml

      -- persistence.xml

    one.jar

    two.jar

    three.jar

     

    where one,two & three contains EJBs and domain classes.

     

    After doing all changes I was expecting things should works but NO luck, so I have to take deep dive and downloaded source code of "hibernate-entitymanager-4.1.6.Final-redhat-3.jar" and "jboss-as-jpa-7.1.3.Final-redhat-4.jar" and found something special in "Ejb3Configuration.java".

    configure method of "Ejb3Configuration.java"  accept "PersistenceUnitInfo" & "java.util.Map" method argument and "PersistenceUnitInfo" instance maintaines list of all jar files (i.e. jar files packaged in EAR file. key of map is EAR name+ jar file name  and value is vfz location iof that jar viz. MyApp.ear/one.jar is key) which are compared by JPA annotation processor to get the actual jar location ( i.e. jar name written in <jar-file> tag of persistence.xml). If we don't give ear name in <jar-file> tag then JPA does not process listed jar files in persistence.xml file.

     

    Here is xml code snippet

     

    <persistence-unit name="testPU" transaction-type="JTA">
       
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jar-file>
    MyApp.ear/one.jar</jar-file>
        <jar-file>MyApp.ear/two.jar</jar-file>

         <jar-file>MyApp.ear/three.jar</jar-file>

    ....

    ....
    ..

    </persistence-unit>

     

    I am not sure it is bug in JBOSS 6 EAP ?