从 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

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

问题描述

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

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.

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

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

我试图做的是使用 jboss-deployment-structure.xml 排除 JPA 子系统,但我发现即使我从 standalone.xml 中注释掉 JPA 扩展和 JPA 子系统并将 JPA 子系统排除在 jboss 中-deployment-structure.xml(也排除 org.hibernate 模块以使用打包在应用程序中的 hibernate),没有运行 JPA 扫描器(如预期)但是任何战争类(在我的情况下)Spring 容器)指的是 javax.persistence 类,API 从 JBoss 模块(modules/system/layers/base/javax/persistence/api/main/hibernate-jpa-2.0-1.0.1.Final-redhat-2.jar!) 代替提供的战争中提供的 API jar.所以很明显我在 JBoss 提供的 API (2.0) 和它的战争应用中的实现(2.1).一个例外是例如,注解 javax.persistence.Table 的索引相关属性不被识别,因为这是 JPA 2.1 中的一个附加项,在 JPA 2.0 中不可用

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

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

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.

这是所有规范 API 类(JBoss 是其中的实现者)将始终优先的有意 JBoss 类加载行为,无论使用的是什么实现,也无论我们告诉它在应用程序中使用特定 API.我认为制作符合特定规范的服务器然后提供覆盖规范版本本身的方法有些矛盾,但有没有一种方法可以让我在我的应用程序中干净地使用 API 和实现?

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 ?

另一种选择是转向实现 JPA 2.1 的 Wildfly,但我的问题是这在 JBoss EAP 6.1 中是否完全可行?

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 ?

推荐答案

如果您是 Maven,这对我有用.

If you're Maven this did the trick for me.

<dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
    </dependency>

jboss-deployment-structure.xml

jboss-deployment-structure.xml

<deployment>

    <exclude-subsystems>
        <subsystem name="jpa" />
    </exclude-subsystems>

    <exclusions>
        <module name="javaee.api" />
    </exclusions>

</deployment>

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

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