为了使用休眠4.3,从JBoss 7.1中排除JPA 2.0 [英] Exclude JPA 2.0 from JBoss 7.1 in order to use hibernate 4.3

查看:171
本文介绍了为了使用休眠4.3,从JBoss 7.1中排除JPA 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



通过在jboss-deployment中添加以下几行代码,我设法将它包含在我的战争中:结构

 <排除项> 
< module name =org.hibernate/>
< /排除>

并在我的pom.xml中添加一个依赖项到hibernate核心和实体管理器中



这使得hibernate 4.3加载,但不幸的是我得到一个错误

  java.lang.NoSuchMethodError :javax.persistence.Table.indexes()[Ljavax / persistence / Index; 

这是由于JPA 2.0在使用JPA 2.1时加载的JPA 2.0造成的



我已经看过这些线索并尝试了他们建议的
从JBoss EAP 6.1中排除JPA子系统 - 尝试在JBoss EAP 6.1中使用JPA 2.1 JBoss AS7自动加载JPA , Hibernate 4.3.0.Final& Spring Data JPA 1.4.3.RELEASE



我用

<$ p添加了一个persistence.xml $ p> < property name =jboss.as.jpa.managedvalue =false/>

从Spring Data中排除了hibernate jpa 2.0

 <依赖性> 
< groupId> org.springframework.data< / groupId>
< artifactId> spring-data-jpa< / artifactId>
< version> $ {spring-data.version}< / version>
<排除项>
<排除>
< groupId> org.hibernate.javax.persistence< / groupId>
< artifactId> hibernate-jpa-2.0-api< / artifactId>
< /排除>
< /排除>
< /依赖关系>

完全从JBoss standalone.xml中删除了JPA子系统,没有任何成功。



唯一能做到的就是在jboss-deployment-structure中排除整个javaee.api,如另一个线程所建议的那样

 <排除> 
< module name =javax.persistence.api/>
< module name =javaee.api/>
< /排除>

但是这导致我的其他代码遇到很多问题。



UPDATE:我的jboss-deployment-structure.xml现在是这样的

 < jboss-deployment-结构> 
< deployment>
<排除项>
< module name =org.slf4j/>
< module name =org.slf4j.impl/>
< module name =org.apache.log4j/>
< module name =javax.persistence.api/>
< module name =org.hibernate/>
< /排除>
<依赖关系>
< module name =org.jboss.ironjacamar.jdbcadapters/>
< module name =org.hornetq/>
< module name =org.hornetq.ra/>
< module name =org.jboss.ejb3/>
< module name =org.jboss.ejb-client/>
< /依赖关系>
< / deployment>
< / jboss-deployment-structure>

正如你所看到的,我已经尝试了很多东西,但没有运气,所以如果有人有另一个想法, 。

解决方案

我会将这个问题分成两个较小的问题:

1)确保你不是依赖于JPA 2.0的传递。为此,你可以使用依赖图可视化工具(NetBeans有一个内置的,或者你可以使用Maven依赖树插件)。
另一种方法是浏览部署到JBoss之前工件中包含的库。



2)确保正确JBoss AS 7.1的配置JBoss AS 7.1与Hibernate 4.0.x jar捆绑在一起,为了更新它们,请尝试按照官方文档




  • 更新当前的 as7 / modules / org / hibernate / main 文件夹以包含更新的版本


  • 删除 as7 / modules / org / hibernate / main 和<$ c $中的* .index文件c> as7 / modules / org / hibernate / envers / main 文件夹

  • 备份当前内容 as7 / modules / org / hibernate 以防万一您犯了错误 删除旧罐子并将新的Hibernate jar复制到 AS7 /模块/ org / hibernate / main + as7 / modules / org / hibernate / envers / main
  • 更新 as7 / modules / org / hibernate / main / module.xml + as7 / modules / org / hibernate / envers / main / module.xml 来命名您复制的罐子




已更新 as7 / modules / org / hibernate / main / module.xml 看起来像(注意依赖关系不会改变):

 <?xml version =1.0encoding =UTF-8?> 

<资源>
< resource-root path =hibernate-core-4.3.5.Final.jar/>
< resource-root path =hibernate-commons-annotations-4.0.4.Final.jar/>
< resource-root path =hibernate-entitymanager-4.3.5.Final.jar/>
< resource-root path =hibernate-infinispan-4.3.5.Final.jar/>
< /资源>

<依赖关系>


< /依赖关系>
< / module>


I want to use hibernate 4.3 for its multitenancy features in JBoss 7.1.

I managed to include it in my war by adding the following lines in jboss-deployment-structure

<exclusions>
   <module name="org.hibernate" />
</exclusions>

and adding a dependency to hibernate core and entity manager in my pom.xml

This made hibernate 4.3 to load but unfortunately I got an error

java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;

which is due to JPA 2.0 being loaded when hibernate 4.3 is using JPA 2.1

I have seen these threads and tried what they suggest Excluding JPA Subsystem from JBoss EAP 6.1 - Trying to use JPA 2.1 in JBoss EAP 6.1, JBoss AS7 Automatically Loading JPA, Hibernate 4.3.0.Final & Spring Data JPA 1.4.3.RELEASE.

I added a persistence.xml with

<property name="jboss.as.jpa.managed" value="false" /> 

excluded hibernate jpa 2.0 from Spring Data

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-jpa</artifactId>
    <version>${spring-data.version}</version>
    <exclusions>
        <exclusion>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Removed JPA subsystem completely from JBoss standalone.xml, without any success.

The only thing that did the trick was to exclude the whole javaee.api in jboss-deployment-structure, as suggested in another thread

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

but this causes many problems to the rest of my code.

UPDATE: my jboss-deployment-structure.xml is now like this

<jboss-deployment-structure>
<deployment>
    <exclusions>
        <module name="org.slf4j" />
        <module name="org.slf4j.impl" />
        <module name="org.apache.log4j" />
        <module name="javax.persistence.api" />
        <module name="org.hibernate" />
    </exclusions>
    <dependencies>
        <module name="org.jboss.ironjacamar.jdbcadapters" />
        <module name="org.hornetq" />
        <module name="org.hornetq.ra" />
        <module name="org.jboss.ejb3" />
        <module name="org.jboss.ejb-client" />
    </dependencies>
</deployment>
</jboss-deployment-structure>

As you see I have tried many things without luck, so if anyone has another idea it is most welcome.

解决方案

I would split this problem into two smaller:

1) Make sure you're not transitively depending on JPA 2.0

For this you can use dependency graph visualization tool (NetBeans have one built in, or you can use a maven dependency tree plugin). Another way would be just to skim through the libs, included in your artifact before deploying to JBoss.

2) Ensure correct configuration of JBoss AS 7.1

JBoss AS 7.1 is bundled with Hibernate 4.0.x jars, in order to update them try out this steps as described in the official doc.

  • update the current as7/modules/org/hibernate/main folder to contain the newer version

  • Delete *.index files in as7/modules/org/hibernate/main and as7/modules/org/hibernate/envers/main folders

  • Backup the current contents of as7/modules/org/hibernate in case you make a mistake

  • Remove the older jars and copy new Hibernate jars into as7/modules/org/hibernate/main + as7/modules/org/hibernate/envers/main

  • Update the as7/modules/org/hibernate/main/module.xml + as7/modules/org/hibernate/envers/main/module.xml to name the jars that you copied in

Updated as7/modules/org/hibernate/main/module.xml will look like (note that dependencies won't change):

<?xml version="1.0" encoding="UTF-8"?>

<module xmlns="urn:jboss:module:1.1" name="org.hibernate">
    <resources>
        <resource-root path="hibernate-core-4.3.5.Final.jar"/>
        <resource-root path="hibernate-commons-annotations-4.0.4.Final.jar"/>
        <resource-root path="hibernate-entitymanager-4.3.5.Final.jar"/>
        <resource-root path="hibernate-infinispan-4.3.5.Final.jar"/>
    </resources>

    <dependencies>
       .
       .
    </dependencies>
</module>

这篇关于为了使用休眠4.3,从JBoss 7.1中排除JPA 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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