Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate 5 issue with JDK 9

I have a Hibernate 5 project that perfectly builds and runs on Java 8. I tried to test it on JDK 9 ea build 171. Since it is a huge project and have other dependencies I had to add java.xml.bind module to the JVM configuration for tests:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.20</version>
    <configuration>
        <argLine>--add-modules java.xml.bind</argLine>
    </configuration>
</plugin>

There were other issues that I could resolve but if used aggregated module java.se.ee(as recommended):

<argLine>--add-modules java.se.ee</argLine>

I got an exception :

java.lang.NoClassDefFoundError: javax/transaction/SystemException
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:374)
    at org.jboss.logging.Logger$1.run(Logger.java:2554)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at org.jboss.logging.Logger.getMessageLogger(Logger.java:2529)

I couldn't even understand why it happened because JTA library(with SystemException class) is in the class-path when tests were running.

Any suggestions on how to fix this?

like image 336
Sergiy Avatar asked Jun 06 '17 09:06

Sergiy


2 Answers

Java SE defines a small subset of JTA. It doesn't include javax.transaction.SystemException as that exception is in the Java EE version of JTA, not the Java SE subset.

When you run with --add-modules java.se.ee then it causes the modules shared between Java SE and Java EE to be resolved, this includes the the java.transaction module. Any attempt to load a type in the javax.transaction package will be loaded from the java.transaction module but since this module only has a small subset of JTA then javax.transaction.SystemException will not be found.

If you drop --add-modules java.se.ee from your command line then you'll find that javax.transaction.SystemException can be loaded, as it's on the class path. So if you only need JAXB (module java.xml.bind) then specify that module to --add-modules, not the "java.se.ee" aggregator that will cause all modules shared with Java EE to be resolved.

like image 91
Alan Bateman Avatar answered Oct 19 '22 02:10

Alan Bateman


Though the question seems old, yet unanswered and since the GA release of JDK is completed. According to the migration guide and the java docs, since the module java.transaction which exports the package javax.transaction has been marked as @Deprecated.

You should ideally migrate your code to be using javaee/javax.transaction instead. Currently, you can do so using automatic module converted from the dependency:

<dependency>
    <groupId>javax.transaction</groupId>
    <artifactId>javax.transaction-api</artifactId>
    <version>1.2</version>
</dependency>

and adding to the module-info.java the following:-

requires javax.transaction.api;

Edit: Thanks to @ImpulseTheFox for verifying that the automatic module name for the jar version 1.3 above requires:-

requires java.transaction;
like image 37
Naman Avatar answered Oct 19 '22 01:10

Naman