diff --git a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateEntityEnhancer.java b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateEntityEnhancer.java index 89d9dfdad455c..5aff66d38e5ff 100644 --- a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateEntityEnhancer.java +++ b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateEntityEnhancer.java @@ -2,9 +2,7 @@ import java.util.function.BiFunction; -import org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext; import org.hibernate.bytecode.enhance.spi.Enhancer; -import org.hibernate.bytecode.enhance.spi.UnloadedField; import org.hibernate.bytecode.spi.BytecodeProvider; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; @@ -13,6 +11,7 @@ import io.quarkus.deployment.QuarkusClassVisitor; import io.quarkus.deployment.QuarkusClassWriter; import io.quarkus.gizmo.Gizmo; +import io.quarkus.hibernate.orm.deployment.integration.QuarkusEnhancementContext; import net.bytebuddy.ClassFileVersion; /** @@ -32,9 +31,11 @@ public final class HibernateEntityEnhancer implements BiFunction loadClass(String name) { + dont(); + return null; + } + + @Override + protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { + dont(); + return null; + } + + @Override + protected Object getClassLoadingLock(String className) { + dont(); + return null; + } + + @Override + protected Class findClass(String name) throws ClassNotFoundException { + dont(); + return null; + } + + @Override + protected Class findClass(String moduleName, String name) { + dont(); + return null; + } + + @Override + protected URL findResource(String moduleName, String name) throws IOException { + dont(); + return null; + } + + @Override + public URL getResource(String name) { + dont(); + return null; + } + + @Override + public Enumeration getResources(String name) { + dont(); + return null; + } + + @Override + public Stream resources(String name) { + dont(); + return null; + } + + @Override + protected URL findResource(String name) { + dont(); + return null; + } + + @Override + protected Enumeration findResources(String name) throws IOException { + dont(); + return null; + } + + /** + * The only implemented method: delegate to the currently set context classloader. + */ + @Override + public InputStream getResourceAsStream(String name) { + return Thread.currentThread().getContextClassLoader().getResourceAsStream(name); + } + + @Override + protected Package definePackage( + String name, + String specTitle, + String specVersion, + String specVendor, + String implTitle, + String implVersion, + String implVendor, + URL sealBase) { + dont(); + return null; + } + + @Override + protected Package getPackage(String name) { + dont(); + return null; + } + + @Override + protected Package[] getPackages() { + dont(); + return null; + } + + @Override + protected String findLibrary(String libname) { + dont(); + return null; + } + + private void dont() { + throw new UnsupportedOperationException("This classloader only supports the #getResourceAsStream() operation"); + } + +} diff --git a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/integration/QuarkusEnhancementContext.java b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/integration/QuarkusEnhancementContext.java new file mode 100644 index 0000000000000..467b615842ca6 --- /dev/null +++ b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/integration/QuarkusEnhancementContext.java @@ -0,0 +1,21 @@ +package io.quarkus.hibernate.orm.deployment.integration; + +import org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext; +import org.hibernate.bytecode.enhance.spi.UnloadedField; + +public final class QuarkusEnhancementContext extends DefaultEnhancementContext { + + @Override + public boolean doBiDirectionalAssociationManagement(final UnloadedField field) { + //Don't enable automatic association management as it's often too surprising. + //Also, there's several cases in which its semantics are of unspecified, + //such as what should happen when dealing with ordered collections. + return false; + } + + @Override + public ClassLoader getLoadingClassLoader() { + return DeferredClassLoader.INSTANCE; + } + +}