gpt4 book ai didi

hibernate - 从 JBoss 7.1 中排除 JPA 2.0 以使用 hibernate 4.3

转载 作者:行者123 更新时间:2023-12-03 09:12:35 25 4
gpt4 key购买 nike

我想在 JBoss 7.1 中使用 hibernate 4.3 的 Multi-Tenancy 功能。

通过在 jboss-deployment-structure 中添加以下几行,我设法将它包含在我的 war 中

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

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

这使 hibernate 4.3 加载但不幸的是我遇到了错误
java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;

这是由于在 Hibernate 4.3 使用 JPA 2.1 时加载了 JPA 2.0

我已经看过这些线程并尝试了它们的建议
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 .

我添加了一个persistence.xml
<property name="jboss.as.jpa.managed" value="false" /> 

从 Spring Data 中排除 hibernate jpa 2.0
<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>

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

正如另一个线程所建议的那样,唯一能解决问题的是在 jboss-deployment-structure 中排除整个 javaee.api
<exclusions>
<module name="javax.persistence.api"/>
<module name="javaee.api"/>
</exclusions>

但这会给我的其余代码带来许多问题。

更新:我的 jboss-deployment-structure.xml 现在是这样的
<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>

如您所见,我尝试了很多事情都没有运气,所以如果有人有其他想法,这是非常受欢迎的。

最佳答案

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

1) 确保您不依赖于 JPA 2.0

为此,您可以使用依赖关系图可视化工具(NetBeans 内置了一个,或者您可以使用 Maven 依赖关系树插件)。
另一种方法是在部署到 JBoss 之前浏览包含在您的工件中的库。

2) 确保正确配置 JBoss AS 7.1

JBoss AS 7.1 与 Hibernate 4.0.x jar 捆绑在一起,为了更新它们,请按照 official doc 中所述尝试这些步骤。 .

  • 更新当前 as7/modules/org/hibernate/main包含较新版本的文件夹
  • 删除 as7/modules/org/hibernate/main 中的 *.index 文件和 as7/modules/org/hibernate/envers/main文件夹
  • 备份 as7/modules/org/hibernate 的当前内容万一你弄错了
  • 移除旧的 jar 并将新的 Hibernate jar 复制到 as7/modules/org/hibernate/main + as7/modules/org/hibernate/envers/main
  • 更新 as7/modules/org/hibernate/main/module.xml + as7/modules/org/hibernate/envers/main/module.xml命名您在
  • 中复制的 jar

    更新 as7/modules/org/hibernate/main/module.xml看起来像(注意依赖项不会改变):
    <?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>

    关于hibernate - 从 JBoss 7.1 中排除 JPA 2.0 以使用 hibernate 4.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23294492/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com