How to configure Jakarta persistence on wildfly 21

947 views Asked by At

Thank you and sorry in advance!

I am working on upgrading our wildfly version from 8 to 21. Back in the days of 8, wildfly shipped with hibernate for the default persistence engine, it appears that now it ships with Jakarta. So, I am going through the process of attempting to get the persistence working and am running into the below-listed errors.

I have a clean download of wildly 21.0.2.Final, I have modified the standalone.xml to include my data sources which I believe are being loaded correctly because these lines that end up in the log.

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>

Here are the errors and warnings that I get when running the ./stabdalone.sh command

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)

In the wildfly-root/modules/system/layers/base/javax/persistence/api/main folder I have the module.xml and the jakarta.persistence-api-2.2.3.jar

module.xml content

<?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>

I have added the Jakarta persistence dependency

<!-- 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>

I also have this, not sure if I need it though.

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

Wondering what dumb thing I am missing?

EDIT: I have added this to the dependencyManagement section:

<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>

And I now get this new error:

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"}}
1

There are 1 answers

5
ehsavoie On

WildFLy is throwing exception when deployment your application. Also You shouldn't link which is an API that is provided by WildFly except if you remove JPA support from WildFly. Also WildFly is compatible with jakartaEE 8 so you shouldn't link your deployment to some API provided by WildFLy. For JakartaEE 9 you should use WildFly preview