Issues

Select view

Select search mode

 
50 of

Add filtration by package name for enhancer

Description

Seems in hibernate 6.2 bytecode enhancement is enabled by default

in org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl#EntityManagerFactoryBuilderImpl

propertyValue = configurationValues.remove( AvailableSettings.ENHANCER_ENABLE_LAZY_INITIALIZATION ); if ( propertyValue != null ) { lazyInitializationEnabled = Boolean.parseBoolean( propertyValue.toString() ); } else { lazyInitializationEnabled = true; }

 

and the it does

if ( dirtyTrackingEnabled || lazyInitializationEnabled || associationManagementEnabled ) { EnhancementContext enhancementContext = getEnhancementContext( dirtyTrackingEnabled, lazyInitializationEnabled, associationManagementEnabled ); persistenceUnit.pushClassTransformer( enhancementContext ); }

 

Probably it does some some good job, but it also starts to produce unexpected exceptions about classes that you don’t use or even know. For example I’m facing some exception OAuth2 security classes from spring while I’m not using spring outh2 security but it has some imports to something else that is actually a root cause.

It is because there is no filtration by class name/package name and it tries to load any class to check if it is entity, interface or not. And this can result that loader can go through the imports and find some imports of classes that are not in the classpath.

I think introducing some file name/package name regex filtration prior loading/processing class will help to mitigate those issues. Just class will be skipped by transformer/enhancer it the very beginning.

Also probably it is a good idea to pre-populate it with well known packages - spring, hibernate, ehcache etc

Details

Assignee

Reporter

Priority

Created June 1, 2023 at 10:03 AM
Updated October 1, 2023 at 1:20 PM

Activity

Marc MarcOctober 1, 2023 at 12:37 PM
Edited

Please - when using the enhancement plugin and doing it statically this creates so many problems when booting up -
It is done statically to avoid module errors that cannot be resolved as one never wants to alter the hibernate core module-info if they are going modular

Caused by: org.hibernate.HibernateException: HHH000488: Bytecode enhancement failed for class: com.guicedee.activitymaster.fsdm.db.entities.arrangement.ArrangementXClassification. It might be due to the Java module system preventing Hibernate ORM from defining an enhanced class in the same package as class com.guicedee.activitymaster.fsdm.db.entities.arrangement.ArrangementXClassification. In this case, the class should be opened and exported to Hibernate ORM.
at org.hibernate.orm.core@6.2.9.Final/org.hibernate.bytecode.internal.bytebuddy.ByteBuddyState.resolveClassLoadingStrategy(ByteBuddyState.java:437)
at org.hibernate.orm.core@6.2.9.Final/org.hibernate.bytecode.internal.bytebuddy.ByteBuddyState$1.run(ByteBuddyState.java:207)
at org.hibernate.orm.core@6.2.9.Final/org.hibernate.bytecode.internal.bytebuddy.ByteBuddyState$1.run(ByteBuddyState.java:201)
at org.hibernate.orm.core@6.2.9.Final/org.hibernate.bytecode.internal.bytebuddy.ByteBuddyState.lambda$load$0(ByteBuddyState.java:214)
at net.bytebuddy@1.14.7/net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:168)
... 73 more
Caused by: java.lang.IllegalAccessException: module org.hibernate.orm.core does not read module com.guicedee.activitymaster.fsdm
at java.base/java.lang.invoke.MethodHandles.privateLookupIn(MethodHandles.java:282)
at org.hibernate.orm.core@6.2.9.Final/org.hibernate.bytecode.internal.bytebuddy.ByteBuddyState.resolveClassLoadingStrategy(ByteBuddyState.java:434)
... 77 more

 

Obviously opening up the module does not resolve the strict encapsulation that hibernate.core does not read from my devloped module xD

From 6.2 it seems that bytecode/proxy does not detect if the classes have been statically enhanced, and then tries to enhance them again. The location specified can be overridden with persistence.xml properties, however this error stills shows as bytebuddy is still trying to enhance a module that is statically enhanced, and the module hibernate.core cannot be set to read child modules

I think 6.2 and up needs to have the detection of statically enhanced classes fixed

Flag notifications