0 Replies Latest reply on Sep 12, 2014 9:11 AM by Leonardo Moretti

    What is the right path to refer a <jar-file> in persistence.xml with JBoss 6.1

    Leonardo Moretti Newbie

      I'm trying to use <jar-file> element in a persistence.xml of an EAR deployed on JBoss 6.1.0.Final.


      As stated in JPA 2.0 specs, one or more JAR files may be specified using the jar-file elements. These jar files contains classes annotated with @Entity.


      According to the JPA 2.0 Specification

      One or more JAR files may be specified using the jar-file elements instead of, or in addition to the mapping files specified in the mapping-file elements. If specified, these JAR files will be searched for managed persistence classes, and any mapping metadata annotations found on them will be processed, or they will be mapped using the mapping annotation defaults defined by this specification. Such JAR files are specified relative to the directory or jar file that contains[82] the root of the persistence unit.[83]


      The following examples illustrate the use of the jar-file element to reference additional persistence classes. These examples use the convention that a jar file with a name terminating in “PUnit” contains the persistence.xml file and that a jar file with a name terminating in “Entities” contains additional persistence classes.


      Example 2:




      lib/earRootPUnit.jar (with META-INF/persistence.xml )


      persistence.xml contains:





      I follow the example of JPA specs, but the entity contained in earEntities.jar are not loaded. Enabling DEBUG level for org.hibernate, I see:


      DEBUG [org.hibernate.ejb.Ejb3Configuration] (HDScanner) Processing PersistenceUnitInfo [

        name: myPersistenceUnit

        persistence provider classname: org.hibernate.ejb.HibernatePersistence

        classloader: BaseClassLoader@750d3251{vfs:///D:/opt/jboss-6.1.0.Final/server/default/deploy/myApp.ear}

        Temporary classloader: null

        excludeUnlistedClasses: false

        JTA datasource: org.jboss.resource.adapter.jdbc.WrapperDataSource@71ff36c5

        Non JTA datasource: org.jboss.resource.adapter.jdbc.WrapperDataSource@71ff36c5

        Transaction type: JTA

        PU root URL: vfs:/D:/opt/jboss-6.1.0.Final/server/default/deploy/myApp.ear/lib/earRootPUnit.jar/

        Shared Cache Mode: null

        Validation Mode: null

        Jar files URLs [


        Managed classes names []

        Mapping files names []

        Properties [


      The path of jar is relative to the deploy directory of the AS, not to the directory or jar file that contains the root of the persistence unit, as stated in JPA specs.


      If I change my jar-file path to:


      jar is found and entity are loaded into persistence loaded.


      But this seems in contrast with JPA specs and it is not good for my needs because I'd like to avoid to use the name of EAR if the persistence.xml.


      Someone can give me some information on which is the correct way to use relative paths in <jar-file>?

      Thanks to all!