3 Replies Latest reply on Jun 22, 2009 8:30 AM by jaikiran

    How to ignore persistence unit loading

    kariem

      I hope this is the right forum to ask this question, as it is JPA-related.

      In my application which is packaged as a WAR I want to access a web service. The web service interface uses classes that are all from a single jar which also defines a persistence unit (META-INF/persistence.xml).

      On deployment of the WAR file, I receive the following error:

      Specification violation [EJB3 JPA 6.2.1.2] - You have not defined a jta-data-source for a JTA enabled persistence context named: xxx


      In the context of this WAR, the persistence unit is not necessary, and it should be possible to ignore/disable the loading of the persistence unit somehow. Does anyone know how I can resolve this issue?

      It is not possible to add a JTA data source to the persistence configuration, as I do not want to change anything in this jar file.

      Thank you,
      Kariem

        • 1. Re: How to ignore persistence unit loading
          jaikiran

          Where in the WAR file is this jar containing persistence.xml located? As far as i know, the WEB-INF/lib folder of an WAR is not scanned for deployments. So that should have skipped the persistence unit from deploying. But i will have to look at this once more to see if that's not how its expected to behave. In the meantime, please post the output of

          jar -tf myapp.war


          where myapp.war is the name of your war file. Also in the output, please let us know the name of the persistence unit jar which is being picked up.


          • 2. Re: How to ignore persistence unit loading
            kariem

            Thank you for taking the time to look at this.

            "jaikiran" wrote:
            Where in the WAR file is this jar containing persistence.xml located? As far as i know, the WEB-INF/lib folder of an WAR is not scanned for deployments. So that should have skipped the persistence unit from deploying. But i will have to look at this once more to see if that's not how its expected to behave.


            The JAR containing the persistence unit is located in WEB-INF/lib/xxx.jar.

            According to the EJB 3 persistence spec (JPA 1.0) section 6.2, the following location may contain the root of a persistence unit (root means the jar file or directory whose META-INF directory contains the persistence.xml):

            • an EJB-JAR file
            • the WEB-INF/classes directory of a WAR file
            • a jar file in the WEB-INF/lib directory of a WAR file
            • a jar file in the root of the EAR
            • a jar file in the EAR library directory
            • an application client jar file


            That means that the persistence unit should be scanned with this type of packaging (item 3 in the list above).

            Is there a way in JBoss (or generally in JEE) to prevent this scanning?

            Thank you,
            Kariem

            • 3. Re: How to ignore persistence unit loading
              jaikiran

              I don't know of any override to prevent this scanning.

              One way i can think of is to add a JBoss specific descriptor (jboss-structure.xml) to the jar containing the persistence.xml. But that would require changing that jar file (which is as good as removing or renaming the persistence.xml).