[hibernate-dev] Using Hibernate ORM as automatic JPMS modules

Gunnar Morling gunnar at hibernate.org
Wed Dec 20 16:47:30 EST 2017

Hi all,

Following to our discussion in Paris, I've created a simple test bed for
showing the usage of Hibernate ORM and its dependencies as automatic
modules for the Java 9 module system:


It pretty much works as expected, I couldn't reproduce the classloader
issue I was mentioning during the meeting. A few things worth noting:

* JDK 9 comes with an incomplete JTA module (java.transaction), so a
complete one must be provided via --upgrade-module-path (I'm using the
2.0.0.Alpha1 version Tomaz Cerar has created for that purpose)
* hibernate-jpa-2.1-api-1.0.0.Final.jar can't be used as an automatic
module, as the automatic naming algorithm stumples upon the numbers (2.1)
within the module name it derives; I'm therefore using my ModiTect tooling (
https://github.com/moditect/moditect/) to convert the JPA API JAR into an
explicit module on the fly

for the actual test, which is run using the module path only (i.e. no

A few things caught my attention:

* When using ByteBuddy as the byte code provider, a reads relationship must
be added from the user's module towards hibernate.core ("requires
hibernate.core"). This is due to the usage of
org.hibernate.proxy.ProxyConfiguration within the generated proxy classes.
Ideally no dependence to the JPA provider should be needed when solely
working with the JPA API (as this demo does), but I'm not sure whether this
can be avoided when using proxies (or could we construct proxies in a way
not requiring this dependence?).

* When using ByteBuddy as the byte code provider, I still needed to have
Javassist around, as it's used in ClassFileArchiveEntryHandler. I
understand that eventually this should be using Jandex, but I'm wondering
whether we could (temporarily) change it to use ASM instead of Javassist
(at least when using ByteBuddy as byte code provider, which is based on
ASM), so people don't need to have Javassist *and* ByteBuddy when using the
latter as byte code provider? This seems desirable esp. once we move to
ByteBuddy by default.

* Multiple methods in ReflectHelper call setAccessible() without checking
whether the method/field/constructor already is accessible. If we changed
that to only call setAccessible() if actually needed, people would have to
be a little bit less permissive in their module descriptor. It'd suffice
for them to declare "exports com.example.entities to hibernate.core"
instead of "opens com.example.entities to hibernate.core", unless they
mandate (private) field access for their entities.

The demo is very simple (insert and load of an entity with a lazy
association). If there's anything else you'd like to try out when using ORM
as JPMS modules, let me know or just fork the demo and try it out yourself



More information about the hibernate-dev mailing list