12 Replies Latest reply on Oct 3, 2011 11:08 AM by Scott Marlow

    Persistence.xml in AS 7

    Shankar Makhija Newbie

      I had a persistence.xml which had multiple jar files (containing entities) defined inside it. This kind of configuration was working in 4.x , but AS 7 seems to be not supporting this.

       

      Also, is it necessary to place the persistence.xml in same jar where we have SLSB defined and want to inject PersistenceUnit into it.

       

      We have a large project that has so many ear files deployed and single persistence unit defined in one common jar file. That doesn't seems to be working now in AS 7.

       

      Thanks in advance,

      Shankar

        • 1. Re: Persistence.xml in AS 7
          jaikiran pai Master

          Shankar Makhija wrote:

           

          I had a persistence.xml which had multiple jar files (containing entities) defined inside it. This kind of configuration was working in 4.x , but AS 7 seems to be not supporting this.

          What error are you seeing?

           

           

          Shankar Makhija wrote:

           

          Also, is it necessary to place the persistence.xml in same jar where we have SLSB defined and want to inject PersistenceUnit into it.

           

          You can use the jar name to access the PU for injection:

           

          @PersistenceContext(unitName="myjar.jar#unitName")

          • 2. Re: Persistence.xml in AS 7
            Shankar Makhija Newbie

            Thanks for the prompt response. I am getting the exception mentioned at bottom.

            Here is the persistence.xml file extract:

             

            <?xml version="1.0" encoding="UTF-8"?>

            <persistence xmlns="http://java.sun.com/xml/ns/persistence"

                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"

                    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence

                    http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">

               <persistence-unit name="MyPersistenceUnit">

             

                    <jta-data-source>java:/jdbc/com/Proj/mgmt/avSysDB</jta-data-source>       

                   

                    <jar-file>some.jar</jar-file>

                    <jar-file>someother.jar</jar-file>

                

                    <properties>

                        <property name="jboss.as.jpa.providerModule" value="org.hibernate:3"/>

                       

                    </properties>

               </persistence-unit>

             

            =========================================================================

            11:43:32,895 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC00001: Failed to start service jboss.persistenceunit."cs_cim_jpa.jar#MyPersistenceUnit": org.jboss.msc.service.StartException in service jboss.persistenceunit."cs_cim_jpa.jar#MyPersistenceUnit": Failed to start service

                    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1786)

                    at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)

                    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_11]

                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_11]

                    at java.lang.Thread.run(Thread.java:619) [:1.6.0_11]

            Caused by: java.lang.RuntimeException: error trying to scan <jar-file>: vfs:/content/upm-persistence.jar

                    at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:831)

                    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:576)

                    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:72)

                    at org.jboss.as.jpa.service.PersistenceUnitService.createContainerEntityManagerFactory(PersistenceUnitService.java:143)

                    at org.jboss.as.jpa.service.PersistenceUnitService.start(PersistenceUnitService.java:77)

                    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)

                    ... 4 more

            Caused by: java.lang.RuntimeException: Missing annotation index to scan entity classes

                    at org.jboss.as.jpa.hibernate3.HibernateAnnotationScanner.getClassesInJar(HibernateAnnotationScanner.java:123)

                    at org.hibernate.ejb.Ejb3Configuration.addScannedEntries(Ejb3Configuration.java:467)

                    at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:828)

                    ... 9 more

            • 3. Re: Persistence.xml in AS 7
              jaikiran pai Master

              That error is fixed in 7.0.2 https://issues.jboss.org/browse/AS7-1602 which has been released today. Please try it against the new release.

              • 4. Re: Persistence.xml in AS 7
                Shankar Makhija Newbie

                Hi Jai,

                I tried JBoss AS 7.0.2 and  found no issues related to  scaning of jars etc. But it didn't map my entities at all. I am getting followin errors:

                Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: TestEntity is not mapped [Select a from TestEntity a]

                 

                These is how I have tried out :


                1.)I created a jar of all my entities say myEntities.jar.

                2.)Kept that jar file inside modules(this module is available to the ear)

                3.)In the ear, I have ejb module , say myService.jar. Inside Meta-inf of this jar, I kept the persistence.xml that mentions the name of the jar file as follows:

                ===============================

                <?xml version="1.0" encoding="UTF-8"?>

                <persistence

                    xmlns="http://java.sun.com/xml/ns/persistence"

                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"

                    version="1.0">

                   

                    <persistence-unit name="MyPersistenceUnit">

                             <jta-data-source>java:/jdbc/com/mgmt/SysDB</jta-data-source>

                             <jar-file>myEntities.jar</jar-file>

                             <!-- <class>service.common.entity.TestEntity</class>  -->

                    </persistence-unit>   

                   

                </persistence>

                ==============================================================

                Instead of <jar-file> , If I use <class> to mention each and every entity class inside persistence.xml, it works perfectly fine. But my problem is, in actual project we have over 100 entity classes which is cumbersome and clumsy to mention like that.

                 

                Thanks,

                Shankar

                • 5. Re: Persistence.xml in AS 7
                  jaikiran pai Master

                  Shankar Makhija wrote:

                   

                  2.)Kept that jar file inside modules(this module is available to the ear)


                               <jar-file>myEntities.jar</jar-file>

                  Where exactly is the myEntities.jar file located?

                  • 6. Re: Persistence.xml in AS 7
                    Shankar Makhija Newbie

                    It's kept alongwith all other jar files inside modules directory. Also, its mentioned in module.xml. And ear has dependency on this module.

                    Apart from that, I tried bundling this jar file in ear/lib as well. But that also didn't work.

                     

                    Where should it be bundled?

                    • 7. Re: Persistence.xml in AS 7
                      Shankar Makhija Newbie

                      I also tried to deploy persistent unit as a separate  jar artifact in deployments (as we are doing in our current setup with JBoss 4.2.x), it says deployed successfully.

                      When I try to inject the PersistenceUnit in some ear (Actually, I need to inject that PU in many ejbs spread across multiple ears deployed in same container), but it failed to inject with following errors:

                       

                      10:40:54,065 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC00001: Failed to start service jboss.deployment.subunit."RTSService.ear"."rtsservice.jar".PARSE: org.jboss.msc.service.StartException in service jboss.deployment.subunit."RTSService.ear"."rtsservice.jar".PARSE: Failed to process phase PARSE of subdeployment "rtsservice.jar" of deployment "RTSService.ear"

                          at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:121)

                          at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824)

                          at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759)

                          at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_11]

                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_11]

                          at java.lang.Thread.run(Thread.java:619) [:1.6.0_11]

                      Caused by: java.lang.IllegalArgumentException: Can't find a deployment unit named SMGRPersistence.jar#SMGRPersistenceUnit at subdeployment "rtsservice.jar" of deployment "RTSService.ear"

                          at org.jboss.as.jpa.container.PersistenceUnitSearch.getPersistenceUnit(PersistenceUnitSearch.java:181)

                          at org.jboss.as.jpa.container.PersistenceUnitSearch.resolvePersistenceUnitSupplier(PersistenceUnitSearch.java:56)

                          at org.jboss.as.jpa.processor.JPAAnnotationParseProcessor.getPersistenceUnit(JPAAnnotationParseProcessor.java:317)

                          at org.jboss.as.jpa.processor.JPAAnnotationParseProcessor.getBindingSource(JPAAnnotationParseProcessor.java:253)

                          at org.jboss.as.jpa.processor.JPAAnnotationParseProcessor.processField(JPAAnnotationParseProcessor.java:151)

                          at org.jboss.as.jpa.processor.JPAAnnotationParseProcessor.processPersistenceAnnotations(JPAAnnotationParseProcessor.java:118)

                          at org.jboss.as.jpa.processor.JPAAnnotationParseProcessor.deploy(JPAAnnotationParseProcessor.java:90)

                          at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:115)

                          ... 5 more

                       

                      -Shankar

                      • 8. Re: Persistence.xml in AS 7
                        Scott Marlow Master

                        You have mentioned multiple ears, following this pattern.  Will each ear contain the SMGRPersistence.jar in ear/lib folder?

                         

                        For the failure to find the persistence unit, try enabled trace logging for org.jboss.as.jpa.  Instructions for enabling are in the troubleshooting section of https://docs.jboss.org/author/display/AS7/JPA+Reference+Guide.

                         

                        Scott

                        • 9. Re: Persistence.xml in AS 7
                          Shankar Makhija Newbie

                          Will each ear contain the SMGRPersistence.jar in ear/lib folder?

                           

                          No. I expect SMGRPersistence.jar to be deployed in deployment folder as one of the artifact. All other ears will simply inject the PersistenceUnit that should be available to them. This is how it is currently packaged and deployed on Jboss 4.2.x and is working fine.

                           

                          If that is not supported then:

                          a.)Will that be supported in upcoming releases of JBoss AS 7.

                          b.)If not, what is the best way to meet such scenario. Here is my current scenario that works under Jboss 4.2.x:

                           

                          1.)We have over 100 entities spread across 2-3 jars i.e. MyEntities1.jar , MyEntities2.jar, MyEntities3.jar. These jars are located in lib folder at present.

                          2.) We have SMGRPersistence.jar that contains persistence.xml in meta-inf. It list down all entity jars mentioned in step 1. This jar is located in deploy folder at present.

                          3.)We have around 10-12 ears using the entities mentioned in step 1, and injecting the PersistenceUnit defined in step2. All these ears are located along with SMGRPersistence.jar in deply folder.

                           

                          This is how it looks like:

                           

                           

                          /JBoss/4.2.3/jboss-4.2.3.GA/jboss-as/server/myserver/deploy/

                          /JBoss/4.2.3/jboss-4.2.3.GA/jboss-as/server/myserver/deploy/SMGRPersistence.jar

                          /JBoss/4.2.3/jboss-4.2.3.GA/jboss-as/server/myserver/deploy/ServiceA.ear

                          /JBoss/4.2.3/jboss-4.2.3.GA/jboss-as/server/myserver/deploy/ServiceB.ear

                          /JBoss/4.2.3/jboss-4.2.3.GA/jboss-as/server/myserver/deploy/ServiceC.ear

                           

                          /JBoss/4.2.3/jboss-4.2.3.GA/jboss-as/server/myserver/lib/MyEntities1.jar

                          /JBoss/4.2.3/jboss-4.2.3.GA/jboss-as/server/myserver/lib/MyEntities2.jar

                          /JBoss/4.2.3/jboss-4.2.3.GA/jboss-as/server/myserver/lib/MyEntities3.jar

                          • 10. Re: Persistence.xml in AS 7
                            Scott Marlow Master

                            Thanks for the details about your deployment, that makes it clearer what you are trying to do.

                             

                            The cleanest way to accomplish deploying your applications, would be a complete repackaging change.  Such that each EAR, would contain the entity classes and persistence.xml.

                             

                            The alternative of sharing the classloaders + persistence.xml for each separate deployment, is not 100% there. 

                             

                            A related forum thread is http://community.jboss.org/message/625912#625912 and a jira requesting support for this is https://issues.jboss.org/browse/AS7-1769.

                             

                            AS mentioned in the above forum thread (search for "8.2.2 Persistence Unit Scope"), each deployment is supposed to contain its own persistence unit definition.  However, I'm not against enhancing the AS7 implementation to  allow separate deployments to share the persistence unit definitions (with proper dependency management via our internal services api).

                             

                            If you want to contribute to resolving AS7-1769, maybe express your interest as a comment in the jira (you should add yourself to the watchers list and vote for it too).  Perhaps also post in the above forum thread to express your interest there.  Personally, I don't have time to help on this at the moment but if  some (community) developers want to help, I can give direction.  I would like to see this solved...

                             

                            Give it some thought and let me know what you want to do.  I'll be interested in knowing what you decide.

                             

                            Scott

                            • 11. Re: Persistence.xml in AS 7
                              Shankar Makhija Newbie

                              Scott,

                              I appreciate your efforts to  take time and understand my scenario. Thanks for guiding me to alternative approach. However it will be combersome to mention the entities as class by class in each persistence.xml.

                              Can I atleast use jar-file tag to include the entire entities jar file in persistence.xml? This jar will be exposed as modules. I'll include the persistence.xml in each ear separately. Will this work? If yes, how can I do this, as I tried few approaches mentioned above but it didn't work?

                               

                              Regarding contribution to AS7-1769, unfortunately I may not be able to spend enough time as I am already running short of time with my schedule for migration to Jboss AS7.

                               

                              Thanks again.

                              -Shankar

                              • 12. Re: Persistence.xml in AS 7
                                Scott Marlow Master

                                Have you tried putting the entities classes into SMGRPersistence.jar and putting SMGRPersistence.jar in each ear/lib folder?

                                 

                                Regarding AS7-1769, perhaps you could register to be notified of when its fixed and maybe help test the solution.