Hibernate ClassCastException隐式命名策略JpaCompliantImpl

时间:2019-05-06 12:01:29

标签: java hibernate java-ee wildfly

我们想在我们的应用程序服务器(Wildfly V16.0)上使用另一个Hibernate版本(5.2.18.Final,JPA 2.1)。 但是我们遇到了以下异常:

{"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"david-app.ear#examplePersistenceUnit\".__FIRST_PHASE__" => "java.lang.ClassCastException: class org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl cannot be cast to class org.hibernate.boot.model.naming.ImplicitNamingStrategy (org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl is in unnamed module of loader 'org.hibernate:5.2.18.Final@5.2.18.Final' @155c18e0; org.hibernate.boot.model.naming.ImplicitNamingStrategy is in unnamed module of loader 'org.hibernate@5.3.9.Final' @102121eb)
Caused by: java.lang.ClassCastException: class org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl cannot be cast to class org.hibernate.boot.model.naming.ImplicitNamingStrategy (org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl is in unnamed module of loader 'org.hibernate:5.2.18.Final@5.2.18.Final' @155c18e0; org.hibernate.boot.model.naming.ImplicitNamingStrategy is in unnamed module of loader 'org.hibernate@5.3.9.Final' @102121eb)"}}

似乎正在尝试同时加载2个休眠版本,但是应通过以下配置避免这种情况:

jboss-deployment-structure.xml(资源/ META-INF):

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
    <exclusions>
        <module name="org.hibernate" slot="main"/>
    </exclusions>
    <dependencies>
        <module name="org.hibernate" slot="5.2.18.Final"/>
    </dependencies>
</deployment>

persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
         http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
         version="2.1">
         <persistence-unit name="examplePersistenceUnit" transaction-type="JTA">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <jta-data-source>jdbc/CoreXADataSource</jta-data-source>
    <properties>
        <property name="jboss.as.jpa.providerModule" value="org.hibernate:5.2.18.Final"/>
        <property name="hibernate.show_sql" value="false"/>
        <property name="hibernate.order_inserts" value="true"/>
        <property name="hibernate.jdbc.wrap_result_sets" value="true"/>
    </properties>
</persistence-unit>

Wildfly中的Hibernate module.xml(5.2.18。最终插槽):

<?xml version="1.0" encoding="UTF-8"?>
<module name="org.hibernate:5.2.18.Final" xmlns="urn:jboss:module:1.8">
<resources>
    <resource-root path="hibernate-core-5.2.18.Final.jar"/>
    <resource-root path="hibernate-entitymanager-5.2.18.Final.jar"/>
    <resource-root path="hibernate-java8-5.2.18.Final.jar"/>
</resources>

<dependencies>
    <module name="com.fasterxml.classmate"/>
    <module name="javax.api"/>
    <module name="javax.annotation.api"/>
    <module name="javax.enterprise.api"/>
    <module name="javax.persistence.api"/>
    <module name="javax.transaction.api"/>
    <module name="javax.validation.api"/>
    <module name="javax.xml.bind.api"/>
    <module name="org.antlr"/>
    <module name="org.dom4j"/>
    <module name="org.javassist" export="true"/>
    <module name="org.jboss.as.jpa.spi"/>
    <module name="org.jboss.jandex"/>
    <module name="org.jboss.logging"/>
    <module name="org.jboss.vfs"/>
    <module name="org.hibernate.commons-annotations"/>
    <module name="org.hibernate.jipijapa-hibernate5" services="import"/>
    <module name="org.infinispan.hibernate-cache" services="import" optional="true"/>
</dependencies>

任何人都知道为什么Wildfly在部署EAR文件时仍然尝试加载其默认的Hibernate版本5.3.9吗?

0 个答案:

没有答案