diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index dead49d39..dbbd63a72 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -23,8 +23,8 @@ micronaut-validation = "4.2.0" managed-vertx = "4.5.0" managed-jooq = "3.18.7" -managed-hibernate = "6.2.13.Final" -managed-hibernate-reactive = "2.0.6.Final" +managed-hibernate = "6.4.0.Final" +managed-hibernate-reactive = "2.2.0.Final" managed-jasync = "2.2.4" managed-jdbi = "3.41.3" diff --git a/hibernate-jpa/src/main/java/io/micronaut/configuration/hibernate/jpa/conf/serviceregistry/builder/supplier/internal/DefaultStandardServiceRegistryBuilderCreatorCreator.java b/hibernate-jpa/src/main/java/io/micronaut/configuration/hibernate/jpa/conf/serviceregistry/builder/supplier/internal/DefaultStandardServiceRegistryBuilderCreatorCreator.java index 56c24d626..5535ae08e 100644 --- a/hibernate-jpa/src/main/java/io/micronaut/configuration/hibernate/jpa/conf/serviceregistry/builder/supplier/internal/DefaultStandardServiceRegistryBuilderCreatorCreator.java +++ b/hibernate-jpa/src/main/java/io/micronaut/configuration/hibernate/jpa/conf/serviceregistry/builder/supplier/internal/DefaultStandardServiceRegistryBuilderCreatorCreator.java @@ -26,9 +26,11 @@ import org.hibernate.boot.registry.BootstrapServiceRegistry; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.integrator.spi.Integrator; +import static org.hibernate.bytecode.internal.BytecodeProviderInitiator.BYTECODE_PROVIDER_NAME_NONE; +import static org.hibernate.cfg.AvailableSettings.BYTECODE_PROVIDER; + /** * Default supplier of {@link StandardServiceRegistryBuilderCreator}. * @@ -54,7 +56,7 @@ public DefaultStandardServiceRegistryBuilderCreatorCreator(@Primary @Nullable In @Override public StandardServiceRegistryBuilder create(JpaConfiguration jpaConfiguration) { if (jpaConfiguration.isCompileTimeHibernateProxies()) { - System.setProperty(AvailableSettings.BYTECODE_PROVIDER, org.hibernate.cfg.Environment.BYTECODE_PROVIDER_NAME_NONE); + System.setProperty(BYTECODE_PROVIDER, BYTECODE_PROVIDER_NAME_NONE); } if (jpaConfiguration.isReactive()) { throw new IllegalStateException("Hibernate Reactive not found on classpath!"); diff --git a/hibernate-jpa/src/main/java/io/micronaut/configuration/hibernate/jpa/proxy/IntroducedHibernateProxyLazyInitializer.java b/hibernate-jpa/src/main/java/io/micronaut/configuration/hibernate/jpa/proxy/IntroducedHibernateProxyLazyInitializer.java index 406f9b992..5f070990d 100644 --- a/hibernate-jpa/src/main/java/io/micronaut/configuration/hibernate/jpa/proxy/IntroducedHibernateProxyLazyInitializer.java +++ b/hibernate-jpa/src/main/java/io/micronaut/configuration/hibernate/jpa/proxy/IntroducedHibernateProxyLazyInitializer.java @@ -16,7 +16,10 @@ package io.micronaut.configuration.hibernate.jpa.proxy; import io.micronaut.core.annotation.Internal; +import org.hibernate.LazyInitializationException; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.persister.entity.EntityPersister; import org.hibernate.proxy.AbstractLazyInitializer; /** @@ -43,4 +46,20 @@ public Class getPersistentClass() { return persistentClass; } + @Override + public Class getImplementationClass() { + if (!isUninitialized()) { + return getImplementation().getClass(); + } + final SharedSessionContractImplementor session = getSession(); + if (session == null) { + throw new LazyInitializationException("could not retrieve real entity class [" + getEntityName() + "#" + getIdentifier() + "] - no Session"); + } + final SessionFactoryImplementor factory = session.getFactory(); + final EntityPersister entityDescriptor = factory.getMappingMetamodel().getEntityDescriptor(getEntityName()); + if (entityDescriptor.getEntityMappingType().hasSubclasses()) { + return getImplementation().getClass(); + } + return persistentClass; + } } diff --git a/hibernate-jpa/src/main/java/io/micronaut/configuration/hibernate/jpa/proxy/IntrospectedHibernateBytecodeProvider.java b/hibernate-jpa/src/main/java/io/micronaut/configuration/hibernate/jpa/proxy/IntrospectedHibernateBytecodeProvider.java index ed3e26abb..bc0aee353 100644 --- a/hibernate-jpa/src/main/java/io/micronaut/configuration/hibernate/jpa/proxy/IntrospectedHibernateBytecodeProvider.java +++ b/hibernate-jpa/src/main/java/io/micronaut/configuration/hibernate/jpa/proxy/IntrospectedHibernateBytecodeProvider.java @@ -18,6 +18,7 @@ import io.micronaut.core.annotation.Internal; import jakarta.inject.Singleton; import org.hibernate.bytecode.enhance.spi.EnhancementContext; +import org.hibernate.bytecode.enhance.spi.EnhancementException; import org.hibernate.bytecode.enhance.spi.Enhancer; import org.hibernate.bytecode.spi.BytecodeProvider; import org.hibernate.bytecode.spi.ProxyFactoryFactory; @@ -37,7 +38,18 @@ @Internal public final class IntrospectedHibernateBytecodeProvider implements BytecodeProvider { - private static final Enhancer NO_OP = (className, originalBytes) -> null; + private static final Enhancer NO_OP = new Enhancer() { + + @Override + public byte[] enhance(String className, byte[] originalBytes) throws EnhancementException { + return null; + } + + @Override + public void discoverTypes(String className, byte[] originalBytes) throws EnhancementException { + // Does nothing + } + }; @Override public ProxyFactoryFactory getProxyFactoryFactory() { diff --git a/hibernate-jpa/src/main/resources/META-INF/native-image/io.micronaut.sql/hibernate-jpa-graal/reflect-config.json b/hibernate-jpa/src/main/resources/META-INF/native-image/io.micronaut.sql/hibernate-jpa-graal/reflect-config.json new file mode 100644 index 000000000..d286af26c --- /dev/null +++ b/hibernate-jpa/src/main/resources/META-INF/native-image/io.micronaut.sql/hibernate-jpa-graal/reflect-config.json @@ -0,0 +1,20 @@ +[ + { + "name": "org.hibernate.dialect.OracleArrayJdbcTypeConstructor", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "name": "org.hibernate.dialect.OracleNestedTableJdbcTypeConstructor", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + } +]