jboss 如何在wildfly 21上配置Jakarta持久性

8nuwlpux  于 2022-11-08  发布在  其他
关注(0)|答案(1)|浏览(161)

谢谢你,对不起提前!
我正在将我们的wildfly版本从8升级到21。早在8的时候,wildfly就附带了默认持久性引擎的hib,现在看来,它附带了Jakarta。所以,我正在尝试让持久性工作,并遇到了下面列出的错误。
我有一个干净的下载wildly 21.0.2.Final,我已经修改了standalone.xml,以包括我的数据源,我相信这些数据源被正确加载,因为这些行结束在日志中。

10:48:46,578 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-3) WFLYJCA0001: Bound data source [java:jboss/datasources/unitTestDS]
10:48:46,578 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-6) WFLYJCA0001: Bound data source [java:jboss/datasources/localLiveDS]

persistence.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">
    <persistence-unit name="ertDatasource">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <jta-data-source>java:jboss/datasources/localLiveDS</jta-data-source>
        <properties>
            <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
            <property name="hibernate.enable_lazy_load_no_trans" value="true"/>
        </properties>
    </persistence-unit>
</persistence>

test-persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="
        http://java.sun.com/xml/ns/persistence
        http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="ertDatasource">
        <jta-data-source>java:jboss/datasources/unitTestDS</jta-data-source>
        <properties>
            <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
            <property name="hibernate.enable_lazy_load_no_trans" value="true"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL9Dialect"/>
        </properties>
    </persistence-unit>
</persistence>

下面是我在运行./ www.example.com命令时收到的错误和警告stabdalone.sh

10:48:41,634 WARN  [org.jboss.as.domain.management.security] (MSC service thread 1-4) WFLYDM0111: Keystore /Applications/Wildfly/wildfly-21.0.2.Final-Clean/standalone/configuration/application.keystore not found, it will be auto generated on first use with a self signed certificate for host localhost

10:48:46,749 WARN  [org.jboss.modules.define] (MSC service thread 1-5) Failed to define class org.hibernate.ejb.HibernatePersistence in Module "deployment.<project name>-api.war" from Service Module Loader: java.lang.IncompatibleClassChangeError: Failed to link org/hibernate/ejb/HibernatePersistence (Module "deployment.<project name>-api.war" from Service Module Loader): class org.hibernate.ejb.HibernatePersistence has interface org.hibernate.ejb.AvailableSettings as super class
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:839)
    at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:424)
    at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:555)
    at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:339)
    at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:126)
    at org.jboss.modules.Module.loadModuleClass(Module.java:731)
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:247)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
    at org.jboss.as.jpa.processor.PersistenceProviderHandler.deploy(PersistenceProviderHandler.java:73)
    at org.jboss.as.jpa.processor.PersistenceBeginInstallProcessor.deploy(PersistenceBeginInstallProcessor.java:49)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:182)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1739)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1701)
    at org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1559)
    at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
    at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
    at java.lang.Thread.run(Thread.java:748)

10:48:46,751 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC000001: Failed to start service jboss.deployment.unit."<project name>-api.war".FIRST_MODULE_USE: org.jboss.msc.service.StartException in service jboss.deployment.unit."<project name>-api.war".FIRST_MODULE_USE: WFLYSRV0153: Failed to process phase FIRST_MODULE_USE of deployment "<project name>-api.war"
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:189)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1739)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1701)
    at org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1559)
    at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
    at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IncompatibleClassChangeError: Failed to link org/hibernate/ejb/HibernatePersistence (Module "deployment.<project name>-api.war" from Service Module Loader): class org.hibernate.ejb.HibernatePersistence has interface org.hibernate.ejb.AvailableSettings as super class
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:839)
    at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:424)
    at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:555)
    at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:339)
    at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:126)
    at org.jboss.modules.Module.loadModuleClass(Module.java:731)
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:247)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
    at org.jboss.as.jpa.processor.PersistenceProviderHandler.deploy(PersistenceProviderHandler.java:73)
    at org.jboss.as.jpa.processor.PersistenceBeginInstallProcessor.deploy(PersistenceBeginInstallProcessor.java:49)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:182)
    ... 8 more

10:48:46,815 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "<project name>-api.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"<project name>-api.war\".FIRST_MODULE_USE" => "WFLYSRV0153: Failed to process phase FIRST_MODULE_USE of deployment \"<project name>-api.war\"
    Caused by: java.lang.IncompatibleClassChangeError: Failed to link org/hibernate/ejb/HibernatePersistence (Module \"deployment.<project name>-api.war\" from Service Module Loader): class org.hibernate.ejb.HibernatePersistence has interface org.hibernate.ejb.AvailableSettings as super class"}}

10:48:46,861 ERROR [org.jboss.as] (Controller Boot Thread) WFLYSRV0026: WildFly Full 21.0.2.Final (WildFly Core 13.0.3.Final) started (with errors) in 22664ms - Started 336 of 599 services (1 services failed or missing dependencies, 373 services are lazy, passive or on-demand)

在wildfly-root/modules/system/layers/base/javax/persistence/api/main文件夹中,我有module.xml和jakarta.persistence-api-2.2.3.jar文件
module.xml内容

<?xml version="1.0" encoding="UTF-8"?>
<module name="javax.persistence.api" xmlns="urn:jboss:module:1.7">
    <dependencies>
        <!-- PersistenceUnitInfo needs javax.sql.DataSource -->
        <module name="javax.api" export="true"/>
    </dependencies>

    <resources>
        <resource-root path="jakarta.persistence-api-2.2.3.jar"/>
    </resources>
</module>

我添加了Jakarta持久性依赖项

<!-- https://mvnrepository.com/artifact/jakarta.persistence/jakarta.persistence-api -->
<dependency>
    <groupId>jakarta.persistence</groupId>
    <artifactId>jakarta.persistence-api</artifactId>
    <version>2.2.3</version>
</dependency>

我也有这个,虽然不确定我是否需要它。

<dependency>
    <groupId>org.hibernate.common</groupId>
    <artifactId>hibernate-commons-annotations</artifactId>
    <version>4.0.4.Final</version>
</dependency>

想知道我错过了什么愚蠢的事情吗?
编辑:我在dependencyManagement部分添加了以下内容:

<dependency>
   <groupId>org.wildfly.bom</groupId>
   <artifactId>wildfly-jakartaee8-with-tools</artifactId>
   <scope>import</scope>
   <type>pom</type>
   <version>21.0.2.Final</version>
</dependency>

现在我得到这个新的错误:

14:20:07,862 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 82) MSC000001: Failed to start service jboss.persistenceunit."eventhub-api.war#ertDatasource": org.jboss.msc.service.StartException in service jboss.persistenceunit."eventhub-api.war#ertDatasource": java.lang.AbstractMethodError
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:198)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:128)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:659)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:213)
    at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
    at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
    at java.lang.Thread.run(Thread.java:748)
    at org.jboss.threads.JBossThread.run(JBossThread.java:513)
Caused by: java.lang.AbstractMethodError
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:276)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:467)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1250)
    at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:170)
    ... 10 more

14:20:07,865 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 2) WFLYCTL0013: Operation ("full-replace-deployment") failed - address: ([]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"eventhub-api.war#ertDatasource\"" => "java.lang.AbstractMethodError
    Caused by: java.lang.AbstractMethodError"}}
tf7tbtn2

tf7tbtn21#

WildFLy在部署应用程序时引发异常。此外,除非从WildFly中删除JPA支持,否则不应链接WildFly提供的API。此外,WildFly与jakartaEE 8兼容,因此不应将部署链接到WildFLy提供的某个API。对于JakartaEE 9,应使用WildFly预览

相关问题