在 EAP 6.4.0 中使用 JPA 2.1 [英] Using JPA 2.1 in EAP 6.4.0
问题描述
我一直在寻找解决这个问题的方法,但没有成功.
I searched for a solution for this problem without having success so far.
我们正在将应用程序迁移到 EAP 6.4.0,而我们的应用程序依赖于 JPA 2.1.但是,JBoss 是 Java EE 6 服务器,因此以模块的形式包含 JPA 2.0.
We're migrating our aplications over to EAP 6.4.0, and our applications relies on JPA 2.1. However, JBoss is a Java EE 6 server, and therefore includes JPA 2.0 in the form of a module.
我尝试将 JPA API jar 直接包含在我的 WEB-INF/lib 目录中,认为类加载器更喜欢这个而不是系统中的那个.
I tried including the JPA API jar directly in my WEB-INF/lib directory, thinking the classloader would prefer this one over the one from the system.
我试图在我的耳朵中包含一个 jboss-deployment-structure.xml 文件.我在ear/META-INF、ear/war/META-INF和ear/war/WEB-INF下试过.
I have tried to include a jboss-deployment-structure.xml file in my ear. I tried it under ear/META-INF, ear/war/META-INF, and ear/war/WEB-INF.
在 jboss-deployment-structure.xml 文件中,我尝试:排除 javax.persistence.api 模块使用 JPA 2.1 创建我自己的模块并为其添加依赖项排除jpa子系统
In the jboss-deployment-structure.xml file, I tried to: exclude the javax.persistence.api module create my own module with JPA 2.1 and add a dependency to it exclude the jpa subsystem
我还尝试将位于 jboss-eap-6.4.0modulessystemlayersasejavaxpersistenceapimain 下的 javax.persistence.api module.xml 文件中的导出属性设置为 false
I also tried to set the export attribute to false in the javax.persistence.api module.xml file located under jboss-eap-6.4.0modulessystemlayersasejavaxpersistenceapimain
我尝试从 standalone.xml 中删除 jpa 子系统.
I tried removing the jpa subsystem from the standalone.xml.
所有这些都导致使用 JPA 2.0 jar.
All of these things resulted in the JPA 2.0 jar being used.
我让它工作的唯一方法是替换模块目录中的实际 jar (jboss-eap-6.4.0modulessystemlayersasejavaxpersistenceapimain).但这不是一个有效的解决方案,因为服务器中的其他应用或服务实际上可能需要旧版本的 API.
The only way I got it to work was to replace the actual jar in the module directory (jboss-eap-6.4.0modulessystemlayersasejavaxpersistenceapimain). But that's not a valid solution as other apps or services in the server may actually need the old version of the API.
有没有办法正确执行此操作(无需迁移到另一台服务器或更改代码)?
Is there a way to do this correctly (without migrating to another server nor changing the code)?
推荐答案
请看:https://issues.jboss.org/browse/WFCORE-209
这是上面链接的副本:
解决方法 1
更新javaee/api/main.module.xml如下:
update the javaee/api/main.module.xml as followed:
<!--<module name="javax.persistence.api" export="true"/>-->
虽然这是不可移植的.
解决方法 2
更新 jboss-deployment-structure.xml 如下:
update jboss-deployment-structure.xml as followed:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclude-subsystems>
<subsystem name="jpa" />
</exclude-subsystems>
<exclusions>
<!-- WFCORE-209 workaround -->
<module name="javaee.api" />
<!-- --------------------- -->
<module name="javax.persistence.api" />
<module name="org.hibernate" />
</exclusions>
<dependencies>
<!-- WFCORE-209 workaround -->
<module name="javax.activation.api" export="true"/>
<module name="javax.annotation.api" export="true"/>
<module name="javax.ejb.api" export="true"/>
<module name="javax.el.api" export="true"/>
<module name="javax.enterprise.api" export="true"/>
<module name="javax.enterprise.deploy.api" export="true"/>
<module name="javax.inject.api" export="true"/>
<module name="javax.interceptor.api" export="true"/>
<module name="javax.jms.api" export="true"/>
<module name="javax.jws.api" export="true"/>
<module name="javax.mail.api" export="true"/>
<module name="javax.management.j2ee.api" export="true"/>
<!-- <module name="javax.persistence.api" export="true"/> -->
<module name="javax.resource.api" export="true"/>
<module name="javax.rmi.api" export="true"/>
<module name="javax.security.auth.message.api" export="true"/>
<module name="javax.security.jacc.api" export="true"/>
<module name="javax.servlet.api" export="true"/>
<module name="javax.servlet.jsp.api" export="true"/>
<module name="javax.transaction.api" export="true"/>
<module name="javax.validation.api" export="true"/>
<module name="javax.ws.rs.api" export="true" services="export"/>
<module name="javax.xml.bind.api" export="true"/>
<module name="javax.xml.registry.api" export="true"/>
<module name="javax.xml.soap.api" export="true"/>
<module name="javax.xml.ws.api" export="true"/>
<!-- This one always goes last. -->
<module name="javax.api" export="true"/>
<!-- --------------------- -->
</dependencies>
</deployment>
</jboss-deployment-structure>
这是完全便携的
这篇关于在 EAP 6.4.0 中使用 JPA 2.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!