Skip to content

Commit

Permalink
Update IntroducedHibernateProxyLazyInitializer and change import of c…
Browse files Browse the repository at this point in the history
…onstant
  • Loading branch information
radovanradic committed Nov 24, 2023
1 parent fb4ed24 commit 636c35a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.bytecode.internal.BytecodeProviderInitiator;
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;

/**
Expand Down Expand Up @@ -56,7 +56,7 @@ public DefaultStandardServiceRegistryBuilderCreatorCreator(@Primary @Nullable In
@Override
public StandardServiceRegistryBuilder create(JpaConfiguration jpaConfiguration) {
if (jpaConfiguration.isCompileTimeHibernateProxies()) {
System.setProperty(BYTECODE_PROVIDER, BytecodeProviderInitiator.BYTECODE_PROVIDER_NAME_NONE);
System.setProperty(BYTECODE_PROVIDER, BYTECODE_PROVIDER_NAME_NONE);
}
if (jpaConfiguration.isReactive()) {
throw new IllegalStateException("Hibernate Reactive not found on classpath!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -45,6 +48,18 @@ public Class<?> getPersistentClass() {

@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;
}
}

0 comments on commit 636c35a

Please sign in to comment.