what is the right path to refer a jar file in jpa persistence.xml in a web app?

前端 未结 4 1245
南旧
南旧 2020-11-27 18:26

persistence.xml looks like this:


    org.hibernate.ejb.Hiber         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 19:13

    Taking a look at jsr always works!

    8.2.1.6.3 Jar Files

    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 pro-cessed, 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 the root of the persis-tence unit.

    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 1:
    app.ear  
       lib/earEntities.jar  
       earRootPUnit.jar (with META-INF/persistence.xml )  
    persistence.xml contains:  
       lib/earEntities.jar  
    
    Example 2:
    app.ear
       lib/earEntities.jar
       lib/earLibPUnit.jar (with META-INF/persistence.xml )
    persistence.xml contains:
       earEntities.jar
    
    Example 3:
    app.ear
       lib/earEntities.jar
       ejbjar.jar (with META-INF/persistence.xml )
    persistence.xml contains:
       lib/earEntities.jar
    
    Example 4:
    app.ear
        war1.war
           WEB-INF/lib/warEntities.jar
           WEB-INF/lib/warPUnit.jar (with META-INF/persistence.xml )
    persistence.xml contains:
        warEntities.jar
    
    Example 5:
    app.ear
       war2.war
          WEB-INF/lib/warEntities.jar
          WEB-INF/classes/META-INF/persistence.xml
    persistence.xml contains:
       lib/warEntities.jar
    
    Example 6:
    app.ear
        lib/earEntities.jar
        war2.war
        WEB-INF/classes/META-INF/persistence.xml
     persistence.xml contains:
        ../../lib/earEntities.jar
    
    Example 7:
    app.ear
       lib/earEntities.jar
       war1.war
       WEB-INF/lib/warPUnit.jar (with META-INF/persistence.xml )
    persistence.xml contains:
       ../../../lib/earEntities.jar
    

    As you see there is no example for war files, all war files in the examples above are inside ear files!
    But I tested in war files and it works just when I specify the absolute path of jar files and it is not a good approach for production environment!

提交回复
热议问题