Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 9, Hibernate and java.sql/javax.transaction

I've tried to "upgrade" a project using Hibernate to Java 9, but I am having problems getting the module to function properly.

The relevant part of my module-info.java looks like this:

module test {

    ...

    requires java.base;
    requires hibernate.core;
    requires javax.transaction;
    requires java.sql;

}

and the relevant dependencies in my POM are

  • org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec, 2.0.0.Alpha1
  • org.hibernate:hibernate-core, 5.2.12.Final
  • javax.transaction:javax.transaction-api, 1.2

The problem is, if I run the program, I get a NoClassDefFoundError for javax.transaction.SystemException. I looked into this, and quite obviously, my module is missing a requires on javax.transaction.

So I add a module dependency on javax.transaction-api. I then go on and attempt to run the program again - now I'm missing java.sql.SQLException.

Here is what I am having a problem with: if I add a dependency on the module java.sql, which contains this class, I end up with a conflict:

module reads package javax.transaction.xa from both java.sql and javax.transaction.api

java.sql and javax.transaction.api contain different packages, and have one in common (javax.transaction.xa), but I require all of them.

How do I deal with this? Is there something simple I am missing?

like image 698
Salem Avatar asked Jan 13 '18 20:01

Salem


1 Answers

Use version 1.3 instead of 1.2 of javax.transaction-api, in this version javax.transaction.xa has been removed.

Maven dependency:

<dependency>
    <groupId>javax.transaction</groupId>
    <artifactId>javax.transaction-api</artifactId>
    <version>1.3</version>
</dependency>
like image 86
cybersoft Avatar answered Nov 04 '22 22:11

cybersoft