一尘不染

Hibernate + Java 9 + javax.transaction.SystemException

hibernate

我可以按照这样的步骤

    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>javax.transaction-api</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.3.0.CR1</version>
        <exclusions>
            <exclusion>
                <groupId>org.jboss.spec.javax.transaction</groupId>
                <artifactId>jboss-transaction-api_1.2_spec</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

+模块信息:

requires javax.transaction.api;

但是该解决方案对我不起作用,因为我仍然遇到错误

[ERROR] error: module org.apache.commons.lang3 reads package javax.transaction.xa from both javax.transaction.api and java.sql

然后,四处浏览,我发现1.3版删除了javax.transaction.xa,所以我去:

    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>javax.transaction-api</artifactId>
        <version>1.3</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.3.0.CR1</version>
        <exclusions>
            <exclusion>
                <groupId>org.jboss.spec.javax.transaction</groupId>
                <artifactId>jboss-transaction-api_1.2_spec</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
  • 模块信息:
    requires java.transaction;
    

    requires java.persistence;
    requires java.sql;
    requires java.naming;
    requires jboss.logging;

现在,我可以成功构建我的JAR。我将该jar导入另一个项目,然后该项目崩溃,如下所示:

NoClassDefFoundErrorjavax/transaction/SystemException
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:374)
at jboss.logging@3.3.1.Final/org.jboss.logging.Logger$1.run(Logger.java:2554)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at jboss.logging@3.3.1.Final/org.jboss.logging.Logger.getMessageLogger(Logger.java:2529)
at jboss.logging@3.3.1.Final/org.jboss.logging.Logger.getMessageLogger(Logger.java:2516)
at org.hibernate.orm.core@5.3.0.CR1/org.hibernate.internal.CoreLogging.messageLogger(CoreLogging.java:28)
at org.hibernate.orm.core@5.3.0.CR1/org.hibernate.internal.CoreLogging.messageLogger(CoreLogging.java:24)
at org.hibernate.orm.core@5.3.0.CR1/org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.<clinit>(ClassLoaderServiceImpl.java:40)
at org.hibernate.orm.core@5.3.0.CR1/org.hibernate.boot.registry.BootstrapServiceRegistryBuilder.build(BootstrapServiceRegistryBuilder.java:218)
at org.hibernate.orm.core@5.3.0.CR1/org.hibernate.boot.registry.StandardServiceRegistryBuilder.<init>(StandardServiceRegistryBuilder.java:58)
at a.data/com.a.data.hibernate.HibernateServiceLocator.<clinit>(HibernateServiceLocator.java:39)
at g.editor/com.g.App.start(App.java:293)

Caused by javax.transaction.SystemException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:374)
at jboss.logging@3.3.1.Final/org.jboss.logging.Logger$1.run(Logger.java:2554)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at jboss.logging@3.3.1.Final/org.jboss.logging.Logger.getMessageLogger(Logger.java:2529)
at jboss.logging@3.3.1.Final/org.jboss.logging.Logger.getMessageLogger(Logger.java:2516)
at org.hibernate.orm.core@5.3.0.CR1/org.hibernate.internal.CoreLogging.messageLogger(CoreLogging.java:28)
at org.hibernate.orm.core@5.3.0.CR1/org.hibernate.internal.CoreLogging.messageLogger(CoreLogging.java:24)
at org.hibernate.orm.core@5.3.0.CR1/org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.<clinit>(ClassLoaderServiceImpl.java:40)
at org.hibernate.orm.core@5.3.0.CR1/org.hibernate.boot.registry.BootstrapServiceRegistryBuilder.build(BootstrapServiceRegistryBuilder.java:218)
at org.hibernate.orm.core@5.3.0.CR1/org.hibernate.boot.registry.StandardServiceRegistryBuilder.<init>(StandardServiceRegistryBuilder.java:58)

我已经尝试:-导入java.se.ee-
将我的JDK从9.0.1更新到9.0.4-将我的JDK更新到10.0.0,这使我陷入了Maven问题,所以我离开了那条路线…我可以在必要时将其取回。-我没有使用故障保护…尽管我尝试了有关添加maven插件:P的StackOverflow答案(是的,现在我愿意尝试逻辑上的东西)。

有人真的解决了这种情况吗?我的意思是在一个模块中hibernate,然后在第二个模块中将其与命名模块一起使用?

非常感谢


阅读 221

收藏
2020-06-20

共1个答案

一尘不染

更新2019/08/05

库已更新,可以提供更好的支持。请使用与以下相同的模块信息定义

opens xx.xx.xx.entities to org.hibernate.orm.core;

requires java.transaction;
requires java.xml.bind;
requires java.sql;
requires java.activation;
requires java.persistence;

Maven已大大简化

<plugin>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <configuration>
                            <annotationProcessorPaths>
                                <annotationProcessorPath>
                                    <groupId>org.hibernate</groupId>
                                    <artifactId>hibernate-jpamodelgen</artifactId>
                                    <version>${maven.hibernate.version}</version>
                                </annotationProcessorPath>
                                <annotationProcessorPath>
                                    <groupId>org.projectlombok</groupId>
                                    <artifactId>lombok</artifactId>
                                    <version>${lombok.version}</version>
                                </annotationProcessorPath>
                                <path>
                                    <groupId>javax.xml.bind</groupId>
                                    <artifactId>jaxb-api</artifactId>
                                    <version>2.3.0</version>
                                </path>
                                <path>
                                    <groupId>javax.annotation</groupId>
                                    <artifactId>javax.annotation-api</artifactId>
                                    <version>1.3.1</version>
                                </path>
                                <path>
                                    <groupId>org.mapstruct</groupId>
                                    <artifactId>mapstruct-processor</artifactId>
                                    <version>${mapstruct.version}</version>
                                </path>
                            </annotationProcessorPaths>
                        </configuration>

                    </plugin>
2020-06-20