从JBoss EAP 6.1中排除JPA子系统 - 尝试在JBoss EAP 6.1中使用JPA 2.1 [英] Excluding JPA Subsystem from JBoss EAP 6.1 - Trying to use JPA 2.1 in JBoss EAP 6.1

查看:264
本文介绍了从JBoss EAP 6.1中排除JPA子系统 - 尝试在JBoss EAP 6.1中使用JPA 2.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含JPA 2.1 API和Hibernate 4.3.0.Final(JPA 2.1实现)的战争应用程序,它使用Spring容器打包并引导,我想在JBoss EAP 6.1中部署它。



我知道JBoss EAP 6.1符合JPA 2.0标准,因此我决定强制JBoss在我的应用程序中使用JPA版本和实现。

什么我试图做的是使用jboss-deployment-structure.xml排除JPA子系统,但是我发现即使我从standalone.xml注释掉JPA扩展和JPA子系统,并将JPA子系统排除在jboss-deployment-structure中.xml(也不包括org.hibernate模块以使用打包在应用程序中的hibernate),没有运行JPA扫描程序(正如预期的那样),但任何war类(在我的情况下为Spring容器)到javax.persistence类,API从JBoss模块加载(modules / system / layers / base / javax / persistence / api / main / hibernate-jpa-2.0-1 .0.1.Final-redhat-2.jar!)INSTEAD提供的战争中提供的API jar。所以很显然,我在JBoss提供的API(2.0)和它的
实现(2.1)在war应用程序中出现了不匹配的异常。
例如,与注释的索引相关的属性javax.persistence.Table不被识别是一个例外,因为这是JPA 2.1中的添加项,并且在JPA 2.0中不可用。



<我可以通过用JPA 2.1替换modules目录中的JPA 2.0 API(并将module.xml指向新的2.1 API jar)来解决此问题,并且一切正常。但是我认为这不是正确的方法,因为这就像试图改变所有应用程序的服务器行为一样。

这是有意的JBoss类加载行为,所有规范API类(其中JBoss是实现者)无论使用哪种实现,都始终优先,无论我们告诉它在应用程序中使用特定的API。我认为制作特定的符合规范的服务器,然后提供
的方式来覆盖spec版本本身有点矛盾,但是有没有办法在我的应用程序中干净地使用API​​和实现?



另一个选择是迁移到JPA 2.1实现的Wildfly,但我的问题是这在JBoss EAP 6.1中是否可行?


您也可以在战争的jboss-deployment-structure.xml中排除jpa子系统:

 < exclude-subsystems> 
< subsystem name =jpa/>
< / exclude-subsystems>
<排除项>
< module name =javaee.api/>
< /排除>


I have a war application which contains JPA 2.1 API and Hibernate 4.3.0.Final ( JPA 2.1 implementation) packaged and bootstrapped using Spring container and I want to deploy this in JBoss EAP 6.1.

I am aware that JBoss EAP 6.1 is JPA 2.0 compliant so I decided to force JBoss to use JPA version and implementation from within my application

What I was trying to do was to exclude the JPA subsystem using jboss-deployment-structure.xml but what I found was that even if I comment out JPA extension and JPA subsystem from standalone.xml and put JPA subsystem exclusion in jboss-deployment-structure.xml (also excluded org.hibernate module to use the hibernate packaged in application), no JPA scanners are run ( as expected) but the moment any of the war class (in my case Spring container) refers to the javax.persistence classes, the API gets loaded from JBoss modules (modules/system/layers/base/javax/persistence/api/main/hibernate-jpa-2.0-1.0.1.Final-redhat-2.jar!) INSTEAD of the API jar supplied in the war supplied. So obviously I get exception of mismatch in the JBoss supplied API (2.0) and its implementation (2.1) in war application. One exception is for e.g., index related property of annotation javax.persistence.Table is not recognized as this is an addition in JPA 2.1 and not available in JPA 2.0

I could work-around this issue by replacing the JPA 2.0 API in the modules directory with JPA 2.1 (and pointing module.xml to the new 2.1 API jar) and everything worked fine. However I think this is not the correct way as this is like trying to change server behaviour for all applications.

Is this the intentional JBoss classloading behaviour that all specification API classes ( of which JBoss is implementer) will always take precedence no matter what the implementation used is and no matter we tell it to use a particular API from within the application. I think that making a particular spec compliant server and then providing way to override the spec version itself is somewhat contradictory but is there a way by which I can cleanly use both the API and implementation from within my application ?

Another option would be to move to Wildfly which is JPA 2.1 implementation, but my question is whether this is cleanly possible in JBoss EAP 6.1 ?

解决方案

We found another solution.
You can also exclude the jpa subsystem in jboss-deployment-structure.xml of the war:

<exclude-subsystems>
    <subsystem name="jpa" />
</exclude-subsystems>
<exclusions>
    <module name="javaee.api" />
</exclusions>

这篇关于从JBoss EAP 6.1中排除JPA子系统 - 尝试在JBoss EAP 6.1中使用JPA 2.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆