javahibernatethorntail

Thorntail 2.6.0.Final "WFLYJCA0114: Failed to load datasource class: com.mysql.cj.jdbc.MysqlXADataSource"


I am using Thorntail (2.6.0) for the first time and have Problems connecting it to my Mysql Database (8.0.18)

I get the following Exception

2019-12-22 17:43:08,832 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 48) WFLYCTL0013: Operation ("add") failed - address: ([
    ("subsystem" => "datasources"),
    ("jdbc-driver" => "mysql")
]) - failure description: "WFLYJCA0114: Failed to load datasource class: com.mysql.cj.jdbc.MysqlXADataSource"

Followed by this Exception

    2019-12-22 17:43:09,981 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
    ("subsystem" => "datasources"),
    ("data-source" => "MainDS")
]) - failure description: {
    "WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.mysql"],
    "WFLYCTL0180: Services with missing/unavailable dependencies" => [
        "org.wildfly.data-source.MainDS is missing [jboss.jdbc-driver.mysql]",
        "jboss.driver-demander.java:jboss/datasources/MainDS is missing [jboss.jdbc-driver.mysql]"
    ]
}
2019-12-22 17:43:09,982 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
    ("subsystem" => "datasources"),
    ("data-source" => "MainDS")
]) - failure description: {
    "WFLYCTL0412: Required services that are not installed:" => [
        "jboss.jdbc-driver.mysql",
        "jboss.jdbc-driver.mysql"
    ],
    "WFLYCTL0180: Services with missing/unavailable dependencies" => [
        "org.wildfly.data-source.MainDS is missing [jboss.jdbc-driver.mysql]",
        "jboss.driver-demander.java:jboss/datasources/MainDS is missing [jboss.jdbc-driver.mysql]",
        "org.wildfly.data-source.MainDS is missing [jboss.jdbc-driver.mysql]"
    ]
}

The Following Settings I already did

I have JAVA_HOME should be Java 8 Zulu on a MacBook with Catalina

I have a module ../src/main/resources/modules/com/mysql/main/module.xml with the Following inside

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

<module xmlns="urn:jboss:module:1.0" name="com.mysql">
    <resources>
        <resource-root path="mysql-connector-java-8.0.18.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
    </dependencies>
</module>

My Persistence.xml in ../src/main/resources/META-INF/persistence.xml has this inside

    <?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="SPU" transaction-type="JTA">

    <!-- The "Java-Transaction-API" datasource here refers to the datasource defined in /src/main/resources/project-defaults.yml. -->
    <jta-data-source>java:jboss/datasources/MainDS</jta-data-source>

    <!-- User and password defines in project-defaults.yml -->
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
        <property name="hibernate.connection.driver_class" value="com.mysql.cj.jdbc.Driver"/>
        <property name="hibernate.show_sql" value="false"/>
        <property name="hibernate.hbm2ddl.auto" value="update"/>
    </properties>
</persistence-unit>
        </persistence>

and my project-defaults.yml in ../src/main/resources/project-defaults.yml has this inside

 thorntail:
  datasources:
    jdbc-drivers:
      mysql:
        driver-module-name: com.mysql
        driver-xa-datasource-class-name: com.mysql.cj.jdbc.MysqlXADataSource
    data-sources:
      MainDS:
        driver-name: mysql
        connection-url: jdbc:mysql://localhost:3306/Mysql
        user-name: ****
        password: ****

I have this in my pom:

<dependency>
  <groupId>io.thorntail</groupId>
  <artifactId>datasources</artifactId>
</dependency>
<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>${version.mysql}</version>
</dependency>

My Database is running and this should be not the problem.

I also read somewhere that there is an error in WildFly, stopping thorntail in finding com.mysql.cj.jdbc.MysqlXADataSource.

I thank everyone who tries to help me, I have this problem the whole day already.

My Goal is a Java-EE Server (FatJar) with JPA and a MySQL Database at the back.


Solution

  • Thorntail can autodetect many JDBC drivers, MySQL included. You don't have to create the module.xml file, and the thorntail.datasources.jdbc-drivers.mysql piece of configuration also isn't necessary. It should be enough to have a dependency on the JDBC driver (which you have), and define the datasource (which you also do). The driver-name should be mysql, which you also already have.

    See https://docs.thorntail.io/2.6.0.Final/#auto-detecting-jdbc-drivers_thorntail and https://docs.thorntail.io/2.6.0.Final/#_datasources for more info.