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 70a00a31ac531..80b6eea0e4376 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 @@ -17,6 +17,7 @@ import io.quarkus.hibernate.orm.deployment.integration.QuarkusClassFileLocator; import io.quarkus.hibernate.orm.deployment.integration.QuarkusEnhancementContext; import net.bytebuddy.ClassFileVersion; +import net.bytebuddy.dynamic.ClassFileLocator; /** * Used to transform bytecode by registering to @@ -101,8 +102,9 @@ public Enhancer getEnhancer() { if (actualEnhancer == null) { synchronized (this) { if (actualEnhancer == null) { - EnhancerClassLocator modelPool = ModelTypePool.buildModelTypePool(QuarkusClassFileLocator.INSTANCE, - CORE_POOL); + EnhancerClassLocator modelPool = new QuarkusModelTypePool( + ModelTypePool.buildModelTypePool(QuarkusClassFileLocator.INSTANCE, + CORE_POOL)); actualEnhancer = PROVIDER.getEnhancer(QuarkusEnhancementContext.INSTANCE, modelPool); } } @@ -111,4 +113,41 @@ public Enhancer getEnhancer() { } } + //This is most likely better solved within Hibernate ORM, but should do for now: + private static class QuarkusModelTypePool implements EnhancerClassLocator { + + private final EnhancerClassLocator delegate; + + private QuarkusModelTypePool(final EnhancerClassLocator delegate) { + this.delegate = delegate; + } + + @Override + public void registerClassNameAndBytes(String s, byte[] bytes) { + this.delegate.registerClassNameAndBytes(s, bytes); + } + + @Override + public void deregisterClassNameAndBytes(String s) { + //Don't do this: we'll have concurrent de-registrations, possibly for the same entry being + //processed by a different thread, when entities are listed as inner classes of other types + //which are also processed. This happens for example in Quarkus integration tests. + } + + @Override + public ClassFileLocator asClassFileLocator() { + return delegate.asClassFileLocator(); + } + + @Override + public Resolution describe(String s) { + return delegate.describe(s); + } + + @Override + public void clear() { + //nope + } + } + }