Hibernate,Java 9和SystemException [英] Hibernate, Java 9 and SystemException

查看:122
本文介绍了Hibernate,Java 9和SystemException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图在Java 9 / Spring Boot 1.5.x / Maven项目中运行Hibernate 5.2.11应用程序,但我在失踪的类中失败:

<$ $ java $ / java.lang.Class.forName0(Native方法)$ b $在java中
在java.base / java.lang.Class.forName0 .base / java.lang.Class.forName(Class.java:375)
at org.jboss.logging.Logger $ 1.run(Logger.java:2554)
在java.base / java。 security.AccessController.doPrivileged(Native方法)
在org.jboss.logging.Logger.getMessageLogger(Logger.java:2529)
在org.jboss.logging.Logger.getMessageLogger(Logger.java:2516 )
在org.hibernate.internal.HEMLogging.messageLogger(HEMLogging.java:28)
在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.SpringHibe rnateJpaPersistenceProvider.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。
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
... 33 more

有没有人遇到这个异常并知道一个解决方法?我尝试为javax.bind或java.se.ee添加 - add-modules ,但它们没有帮助。



上面的错误显示在使用Hibernate启动Spring上下文的mavan-failsafe(2.20.1)集成测试中。
应用程序没有任何Java 9特定的代码。 根据迁移指南和java文档,因为模块 导出包 javax.transaction 的java.transaction 已被标记为 @Deprecated

理想情况下,您应该将代码迁移到使用而不是javaee / javax.transaction 。目前,您可以使用从依赖关系转换来的自动模块完成此操作:

 < dependency> 
< groupId> javax.transaction< / groupId>
< artifactId> javax.transaction-api< / artifactId>
< version> 1.2< / version>
< /依赖关系>

并添加到 module-info.java 以下内容: -

 需要javax.transaction.api; 






另外,当使用 maven-failsafe-plugin ,请确保您使用 2.20.1 或更高版本://cwiki.apache.org/confluence/display/MAVEN/Java+9+-+Jigsawrel =nofollow noreferrer> Maven的进度文档。

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






@Deprecated(forRemoval =after OP的确认书)



另一方面,临时解决方法(因为最终这些模块将从JDK中删除)可以使用: -

   -  add-modules java.transaction 

正如在注释中提到的那样,由于类路径中已经存在 javax.transaction-api 所需的依赖项,所以您应该不需要添加任何编译器选项,否则你最终会用 java.transaction 模块导出的 javax.transaction 来覆盖当前的包。 code> package理想情况下用于你的用例不包含 SystemException


I've been trying to run Hibernate 5.2.11 application in Java 9/Spring Boot 1.5.x/Maven project but I'm failing at missing 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 encountered this exception and knows a workaround? I tried adding --add-modules for javax.bind or java.se.ee but they didn't help.

The above error shows in a mavan-failsafe (2.20.1) integration test that starts Spring context with Hibernate. Application doesn't have any Java 9 specific code.

解决方案

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;


Additionally while using the maven-failsafe-plugin, make sure you are using the minimum compatible version 2.20.1 or above as mentioned in the progress document of Maven.

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


@Deprecated(forRemoval="after OP's confirmation")

On the other hand, a temporary workaround (since eventually these modules will be removed from the JDK) could be to make use of:-

--add-modules java.transaction

As mentioned in the comments, since the required dependency for javax.transaction-api is already available on the classpath, you shouldn't be required to add any compiler option or else you would end up overriding the current package with the java.transaction module's exported javax.transaction package which ideally for your use case doesn't consist of SystemException.

这篇关于Hibernate,Java 9和SystemException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆