Bob*_*obo 22 persistence hibernate jpa war java-ee-6
persistence.xml看起来像这样:
<persistence-unit name="testPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>jdbc/test</non-jta-data-source>
<jar-file>../../lib/app-services-1.0.jar</jar-file>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)
它是一个Web项目,因此部署单元是一个war文件.我试图引用的jar文件在WEB-INF/lib /文件夹中,persistence.xml在WEB-INF/classes/META-INF文件夹中.部署时,它只是告诉我
"警告:无法找到文件(忽略):file:.../../lib/app-services-1.0.jar".
我也试过,我能想到的,即每一个可能的路径../lib/app-services-1.0.jar,LIB /应用服务-1.0.jar.
这样做的正确途径是什么?
Hei*_*deh 21
看看jsr总是有效!
8.2.1.6.3 Jar文件
可以使用
jar-file元素来指定一个或多个JAR文件,而不是mapping-file元素中指定的映射文件,或者除了元素中指定的映射文件之外.如果指定,将搜索这些JAR文件以查找托管持久性类,并且将对其上找到的任何映射元数据注释进行处理,或者将使用此规范定义的映射注释默认值对它们进行映射.此类JAR文件是相对于包含persis-tence单元根目录的目录或jar文件指定的.以下示例说明了使用该
jar-file元素引用其他持久性类.这些示例使用以下惯例:名称以"PUnit"结尾的jar文件包含该persistence.xml文件,并且名称以"Entities"结尾的jar文件包含其他持久性类.
Example 1:
app.ear
lib/earEntities.jar
earRootPUnit.jar (with META-INF/persistence.xml )
persistence.xml contains:
<jar-file>lib/earEntities.jar</jar-file>
Example 2:
app.ear
lib/earEntities.jar
lib/earLibPUnit.jar (with META-INF/persistence.xml )
persistence.xml contains:
<jar-file>earEntities.jar</jar-file>
Example 3:
app.ear
lib/earEntities.jar
ejbjar.jar (with META-INF/persistence.xml )
persistence.xml contains:
<jar-file>lib/earEntities.jar</jar-file>
Example 4:
app.ear
war1.war
WEB-INF/lib/warEntities.jar
WEB-INF/lib/warPUnit.jar (with META-INF/persistence.xml )
persistence.xml contains:
<jar-file>warEntities.jar</jar-file>
Example 5:
app.ear
war2.war
WEB-INF/lib/warEntities.jar
WEB-INF/classes/META-INF/persistence.xml
persistence.xml contains:
<jar-file>lib/warEntities.jar</jar-file>
Example 6:
app.ear
lib/earEntities.jar
war2.war
WEB-INF/classes/META-INF/persistence.xml
persistence.xml contains:
<jar-file>../../lib/earEntities.jar</jar-file>
Example 7:
app.ear
lib/earEntities.jar
war1.war
WEB-INF/lib/warPUnit.jar (with META-INF/persistence.xml )
persistence.xml contains:
<jar-file>../../../lib/earEntities.jar</jar-file>
Run Code Online (Sandbox Code Playgroud)
如您所见,没有war文件的示例,上面示例中的所有war文件都是内部文件!
但是我在war文件中进行了测试,它只是在我指定jar文件的绝对路径时才有效,对于生产环境来说它不是一个好方法!
小智 12
以防万一其他人偶然发现:jar-file-statement只有效.当持久性单元作为Enterprise Archives(.ear)的一部分进行部署时 - 在所有其他情况下(.war),persistence.xml必须驻留在/ META-INF /中,并且不能引用驻留在持久性单元之外的类(见:http://javahowto.blogspot.com/2007/06/where-to-put-persistencexml-in-web-app.html).所以,据我所知,没有办法让一个persistence.xml存在于WEB-INF/classes/META-INF中,它引用了不在WEB-INF/classes中的类.
Pra*_* M 8
war2.war
WEB-INF/lib/warEntities.jar
WEB-INF/classes/META-INF/persistence.xml
persistence.xml contains:
<jar-file>lib/warEntities.jar</jar-file>
Run Code Online (Sandbox Code Playgroud)
此格式适用于war文件.我使用Wildlfy 8.2.0和JPA 2.1
| 归档时间: |
|
| 查看次数: |
30975 次 |
| 最近记录: |