Hibernate, Java 9, and SystemException

I am trying to run a Hibernate 5.2.11 application in a Java 9 / Spring Boot 1.5.x / Maven project, but I am missing a class:

Caused by: java.lang.NoClassDefFoundError: javax/transaction/SystemException at java.base/java.lang.Class.forName0(Native Method) at java.base/java.lang.Class.forName(Class.java:375) 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) at org.jboss.logging.Logger.getMessageLogger(Logger.java:2516) at org.hibernate.internal.HEMLogging.messageLogger(HEMLogging.java:28) at org.hibernate.internal.HEMLogging.messageLogger(HEMLogging.java:24) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<clinit>(EntityManagerFactoryBuilderImpl.java:115) at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:54) at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ... 33 more 

Has anyone come across this exception and know a workaround? I tried adding --add-modules for javax.bind or java.se.ee, but they did not help.

The above error is shown in the mavan-failafe integration test (2.20.1), which runs the Spring context with Hibernate. The application does not have special Java 9 code.

+5
source share
2 answers

According to the migration guide and java docs, since the java.transaction module that exports the javax.transaction package javax.transaction been marked as @Deprecated .

Ideally, you should port your code to javaee / javax.transaction . Currently, you can do this using an automatic module converted from a dependency:

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

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

 requires javax.transaction.api; 

Also, when using the maven-failsafe-plugin make sure that you are using the minimum compatible version 2.20.1 or higher, as indicated in the Maven progress document.

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.20.1</version> </plugin> 

@Deprecated (forRemoval = "after confirmation by OP")

On the other hand, a temporary workaround (as these modules will ultimately be removed from the JDK) can be used: -

 --add-modules java.transaction 

As mentioned in the comments, since the required dependency for javax.transaction-api already available in the classpath, you do not need to add any compiler parameter, otherwise you must block the current package using java.transaction exported javax.transaction module, which is perfect for your use, does not consist of a SystemException .

+2
source

This is what I think: --add-modules java.se.ee according to Modules shared with Java EE, not enabled by default , will allow all Java EE Modules used to enable internal APIs . Therefore, developers do not need to add a specific module one by one. On the other hand, JDK9 also separates EE from SE. javax.transaction.SystemException no longer in the JDK9 library, but is in the EE library. Like in java.se.ee module-info:

 @SuppressWarnings({"deprecation", "removal"}) @Deprecated(since="9", forRemoval=true) module java.se.ee { requires transitive java.se; // Upgradeable modules for Java EE technologies requires transitive java.activation; requires transitive java.corba; requires transitive java.transaction; requires transitive java.xml.bind; requires transitive java.xml.ws; requires transitive java.xml.ws.annotation; } 

But for the java.transaction module java.transaction it only has: InvalidTransactionException, TransactionRequiredException, TransactionRolledbackException

0
source

Source: https://habr.com/ru/post/1272264/


All Articles