7 Replies Latest reply on Mar 18, 2012 10:55 PM by Mostafa Far

    Entity classes in different jars are not scanned by <jar-file> in persistence.xml

    Mostafa Far Newbie

      Hi,

       

      There is an application that is migrated from jboss 4.3 to Jboss 7 CR1b. There are several ejb-jar modules, each module with one persistence.xml, in an ear package.All of the persistence.xml files have the same unit-name.

       

      The problem is that the entity classes can not be found when it refers to a different module even though the module/jar is included with <jar-file> in persistence.xml. This cuases errors during deployment like:

      Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on my.com.infopro.icba10.kernel.security.transaction.domain.UserLimit.user references an unknown entity: my.com.infopro.icba10.kernel.userprofile.domain.User

       

      Or like this one after successful deployment

      :

      Caused by: java.lang.IllegalArgumentException: Unknown entity: my.com.infopro.icba10.kernel.activitytrail.domain.ActivityLog

       

      Once the entity that cuased the error is added to the persistence.xml the error will be resolved.

       

      This is a persistence.xml of one of the modules:

       

      <?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="entityManager" transaction-type="JTA">
        <jta-data-source>java:/ICBA10DS</jta-data-source>
        <jar-file>../../iicba10-kern-userprofile-ejb.jar</jar-file>
        <jar-file>../../iicba10-kern-audittrail-ejb.jar</jar-file>
        <!--
        <class>my.com.infopro.icba10.kernel.userprofile.domain.User</class>
        <class>my.com.infopro.icba10.kernel.activitytrail.domain.ActivityLog</class>
        -->
        <properties>
          <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect" />
          <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
         </properties>
       </persistence-unit>
      </persistence>
      
        
      

       

      I already noticed about this issue: https://community.jboss.org/message/635691

      and this fix: https://issues.jboss.org/browse/AS7-2497https://issues.jboss.org/browse/AS7-2497

      So I shoould expect the fixes have been appliyed also to the current version (Jboss 7 CR1b) that I am using. but I still have the similar problem with the difference that i have multiple persistence.xml in the ear.

       

      As far as the that above config works fine in Jboss 4.3. why it needs each enity class from different module to be included in persistence.xml in Jboss 7?

       

      I will be very thankful for your help.

        • 1. Re: Entity classes in different jars are not scanned by <jar-file> in persistence.xml
          Scott Marlow Master

          AS7-2497 is fixed in AS 7.1.0 (Beta 1 build).  From your description of the version that your using, I'm not sure which version you are using.  I don't think it will make a difference but its always best to try the latest community release (or build).  AS 7.1.1 was just released, you could try that

           

          It might be helpful if you show us the contents of your ear.  Do you have a jboss-deployment-structure.xml?  Show us the contents of that also.

          • 2. Re: Entity classes in different jars are not scanned by <jar-file> in persistence.xml
            Mostafa Far Newbie

            Thanks Scott, the current version I am using is "7.1.0.CR1b" which was released after "7.1.0.Beta1" that above fix was applied to. Actually, the time i started the migration process the 7.1.0.CR1b was the latest one. However, the time the 7.1.0 Final was relased i tried it and noticed that it forces me (regarding to this: https://issues.jboss.org/browse/AS7-2634) to include the "<session-type>Stateless</session-type>" (though the beans are annotated with @Stateless) for all session beans of my app which the number of them goes over hundreds. So we decided to temporary postpone it to after successful migration to 7.1.0.CR1b.

             

            This is the content of my ear:

             

            C:\APP_SERVER\jboss-as-7.1.0.CR1b\standalone\deployments>jar -tf icba10.ear
            icba10-kern-audittrail-ejb.jar
            icba10-kern-core-ejb.jar
            icba10-kern-security-ejb.jar
            icba10-kern-userprofile-ejb.jar
            (...and many other ejb-jars)
            lib/
            lib/log4j-xml.jar
            META-INF/
            META-INF/application.xml
            META-INF/jboss-deployment-structure.xml
            META-INF/MANIFEST.MF

            and this is the strucute of one my ejb-jars:

             

            META-INF/
            META-INF/ejb-jar.xml
            META-INF/MANIFEST.MF
            META-INF/persistence.xml
            my/com/...(classes)

            and this is the jboss-deployment-structure.xml :

             

            <?xml version="1.0" encoding="UTF-8"?>
            <jboss-deployment-structure>
              <!-- Make sub deployments isolated by default, so they cannot see each others classes without a Class-Path entry -->
              <ear-subdeployments-isolated>false</ear-subdeployments-isolated>
              <!-- This corresponds to the top level deployment. For a war this is the war's module, for an ear -->
              <!-- This is the top level ear module, which contains all the classes in the EAR's lib folder     -->
              <deployment>
                <!-- Exclusions allow you to prevent the server from automatically adding some dependencies     -->
                <exclusions>
                </exclusions>
                <!-- This allows you to define additional dependencies, it is the same as using the Dependencies: manifest attribute -->
                <dependencies>
                  <module name="com.infopro.icba10" slot="main" export="true"/>
                  <module name="javax.jws.api" slot="main" export="true"/>
                  <module name="org.jboss.ws.api" slot="main" export="true"/>
                </dependencies>
                <!-- These add additional classes to the module. In this case it is the same as including the jar in the EAR's lib directory -->
                <resources>
                </resources>
              </deployment>
            </jboss-deployment-structure>
            
             
            

             

            Thanks alot for you help

            • 3. Re: Entity classes in different jars are not scanned by <jar-file> in persistence.xml
              Scott Marlow Master

              Can you enable TRACE logging for JPA and org.hibernate.  Follow these instructions for doing that for JPA and also add the following:

               

              <logger category="org.hibernate">

                      <level name="TRACE" />

                   </logger>

               

              Then deploy the application and attach the as7/standalone/log/server.log here.

               

              We will see a lot of log messages when scanning for entities.  I'm hoping that will give a hint.

              1 of 1 people found this helpful
              • 4. Re: Entity classes in different jars are not scanned by <jar-file> in persistence.xml
                Mostafa Far Newbie

                By enabling the TRACE logging I noticed that JBoss 7 was looking for the jars in follwoing location:

                Jar files URLs [
                  vfs:/C:/APP_SERVER/jboss-as-7.1.0.CR1b/standalone/iicba10-kern-audittrail-ejb.jar
                  vfs:/C:/APP_SERVER/jboss-as-7.1.0.CR1b/standalone/iicba10-kern-userprofile-ejb.jar

                therefore, I deleted the "../../i" path from :

                 

                <jar-file>../../iicba10-kern-userprofile-ejb.jar</jar-file>

                Changed  to:

                <jar-file>icba10-kern-userprofile-ejb.jar</jar-file>

                (In Jboss 4.3 the extra character (in our case "i") was needed to be added to the names of jars for relative path due to an issue with jboss 4.3: https://community.jboss.org/thread/26579 )

                 

                After above change, Jboss 7 can see the jars and it works fine. Now i have to change all my persistence.xml files and their <jar-file> as part of migration from Jboss 4.3 to Jboss 7. If the same thing is true for jboss 5, and jboss 6 its nice to include that in the migration guide.

                 

                Scott, Thank you very much for your help .

                • 5. Re: Entity classes in different jars are not scanned by <jar-file> in persistence.xml
                  Stephen Coy Master

                  I was researching this for you and you beat me to the punch!

                   

                  In any event, the JPA 2.0 spec has this to say about the jar-file element:

                   

                  Due to ambiguity in the Java Persistence 1.0 specification, provider-specific interpretation of the relative references used by this element may apply to earlier versions.

                   

                  so that may at least explain the behaviour you're seeing after the port.

                  • 6. Re: Entity classes in different jars are not scanned by <jar-file> in persistence.xml
                    Scott Marlow Master

                    Its good that we have an understanding of what happened now.  I wonder if deploying the current application, as an exploded deployment, would have any impact on any of this.

                     

                    If you try that, https://docs.jboss.org/author/display/AS71/Admin+Guide mentions that you can create a YourEARName.ear.dodeploy marker file to get the exploded (contents extracted into as7/standalone/deploy/YourAppName.ear folder) app to deploy.

                     

                    If the exploded behaviour is different, I'd like to know about that.  If you haven't started making app changes yet.

                     

                    Scott

                    • 7. Re: Entity classes in different jars are not scanned by <jar-file> in persistence.xml
                      Mostafa Far Newbie

                      Thanks Stephen, it's good to know that.

                       

                      Scott, I tested the application in exploded mode with the above changes( the omission of "../../i") and it works perfectly though a difference (content vs deployments) can be seen on the logs for the URLs.

                       

                      As an ear package file deployment:

                      PU root URL: vfs:/C:/APP_SERVER/jboss-as-7.1.0.CR1b/standalone/content/icba10.ear/icba10-kern-security-ejb.jar/
                      Shared Cache Mode: UNSPECIFIED
                      Validation Mode: AUTO
                      Jar files URLs [
                        vfs:/C:/APP_SERVER/jboss-as-7.1.0.CR1b/standalone/content/icba10.ear/icba10-kern-userprofile-ejb.jar/
                        vfs:/C:/APP_SERVER/jboss-as-7.1.0.CR1b/standalone/content/icba10.ear/icba10-kern-audittrail-ejb.jar/]

                       

                       

                      As an exploded deployment:

                       

                      PU root URL: vfs:/C:/APP_SERVER/jboss-as-7.1.0.CR1b/standalone/deployments/icba10.ear/icba10-kern-security-ejb.jar/
                      Shared Cache Mode: UNSPECIFIED
                      Validation Mode: AUTO
                      Jar files URLs [
                        vfs:/C:/APP_SERVER/jboss-as-7.1.0.CR1b/standalone/deployments/icba10.ear/icba10-kern-userprofile-ejb.jar/
                        vfs:/C:/APP_SERVER/jboss-as-7.1.0.CR1b/standalone/deployments/icba10.ear/icba10-kern-audittrail-ejb.jar/]