简体   繁体   中英

generating ORM with hibernate in Java 9 application

I'm trying to generate ORM using hibernate I'm using oracle 11g database and I'm getting this error after making hibernate code generation configuration

java.lang.reflect.InaccessibleObjectException: Unable to make field java.util.ArrayList jdk.internal.loader.URLClassPath.loaders accessible: module java.base does not "opens jdk.internal.loader" to unnamed module @6a75c1c8
Unable to make field java.util.ArrayList jdk.internal.loader.URLClassPath.loaders accessible: module java.base does not "opens jdk.internal.loader" to unnamed module @6a75c1c8
java.lang.reflect.InaccessibleObjectException: Unable to make field java.util.ArrayList jdk.internal.loader.URLClassPath.loaders accessible: module java.base does not "opens jdk.internal.loader" to unnamed module @6a75c1c8
Unable to make field java.util.ArrayList jdk.internal.loader.URLClassPath.loaders accessible: module java.base does not "opens jdk.internal.loader" to unnamed module @6a75c1c8

and this is my Hibernate.cfg.xml :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.password">compte</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
        <property name="hibernate.connection.username">compte</property>
        <property name="hibernate.default_schema">COMPTE</property>
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
    </session-factory>
</hibernate-configuration>

The exception seems justified if there is a type on your classpath which is trying to access the jdk.internal.loader.URLClassPath which is used as an internal class in the JDK and is exported specifically to java.desktop , java.instrument and java.logging only.

A little more about the unnamed module :-

The unnamed module reads every other module. Code in any type loaded from the class path will thus be able to access the exported types of all other readable modules, which by default will include all of the named , built-in platform modules .

An alternate of accessing the package(in which the class resides) is by using the VM args ::

--add-opens java.base/jdk.internal.loader=ALL-UNNAMED

which would add a readability edge by opening the package jdk.internal.loader within the java.base module to all unnamed modules.

But ideally, a solution should be proposed/reached to move away from opening an internal package to access such a class which would be more clear when you look at the source of this error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM