HHH-16952 Discover embeddable types through @Embedded annotation for enhancement in a pre-discovery phase

This commit is contained in:
Christian Beikov 2023-08-07 11:40:32 +02:00
parent 13bc7ff38c
commit ea9a91502f
8 changed files with 25 additions and 22 deletions

View File

@ -341,17 +341,15 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
);
persistenceUnit.pushClassTransformer( enhancementContext );
if ( !persistenceUnit.getClassTransformers().isEmpty() ) {
final ClassTransformer classTransformer = persistenceUnit.getClassTransformer();
if ( classTransformer != null ) {
final ClassLoader classLoader = persistenceUnit.getTempClassLoader();
if ( classLoader == null ) {
throw persistenceException( "Enhancement requires a temp class loader, but none was given." );
}
for ( ClassTransformer classTransformer : persistenceUnit.getClassTransformers() ) {
for ( PersistentClass entityBinding : metadata.getEntityBindings() ) {
if ( entityBinding.getClassName() != null ) {
classTransformer.discoverTypes( classLoader, entityBinding.getClassName() );
}
for ( PersistentClass entityBinding : metadata.getEntityBindings() ) {
if ( entityBinding.getClassName() != null ) {
classTransformer.discoverTypes( classLoader, entityBinding.getClassName() );
}
}
}

View File

@ -194,7 +194,7 @@ public class ParsedPersistenceXmlDescriptor implements org.hibernate.jpa.boot.sp
}
@Override
public Collection<ClassTransformer> getClassTransformers() {
return Collections.emptyList();
public ClassTransformer getClassTransformer() {
return null;
}
}

View File

@ -11,6 +11,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Properties;
import jakarta.persistence.PersistenceException;
import jakarta.persistence.SharedCacheMode;
import jakarta.persistence.ValidationMode;
import jakarta.persistence.spi.PersistenceUnitInfo;
@ -26,7 +28,7 @@ import org.hibernate.jpa.internal.enhance.EnhancingClassTransformerImpl;
*/
public class PersistenceUnitInfoDescriptor implements PersistenceUnitDescriptor {
private final PersistenceUnitInfo persistenceUnitInfo;
private final ArrayList<ClassTransformer> classTransformers = new ArrayList<>();
private ClassTransformer classTransformer;
public PersistenceUnitInfoDescriptor(PersistenceUnitInfo persistenceUnitInfo) {
this.persistenceUnitInfo = persistenceUnitInfo;
@ -114,16 +116,19 @@ public class PersistenceUnitInfoDescriptor implements PersistenceUnitDescriptor
@Override
public void pushClassTransformer(EnhancementContext enhancementContext) {
if ( this.classTransformer != null ) {
throw new PersistenceException( "Persistence unit [" + persistenceUnitInfo.getPersistenceUnitName() + "] can only have a single class transformer." );
}
// During testing, we will return a null temp class loader in cases where we don't care about enhancement
if ( persistenceUnitInfo.getNewTempClassLoader() != null ) {
final EnhancingClassTransformerImpl classTransformer = new EnhancingClassTransformerImpl( enhancementContext );
classTransformers.add( classTransformer );
this.classTransformer = classTransformer;
persistenceUnitInfo.addTransformer( classTransformer );
}
}
@Override
public Collection<ClassTransformer> getClassTransformers() {
return classTransformers;
public ClassTransformer getClassTransformer() {
return classTransformer;
}
}

View File

@ -88,5 +88,5 @@ public interface PersistenceUnitDescriptor {
void pushClassTransformer(EnhancementContext enhancementContext);
Collection<ClassTransformer> getClassTransformers();
ClassTransformer getClassTransformer();
}

View File

@ -253,8 +253,8 @@ public abstract class BaseJpaOrNativeBootstrapFunctionalTestCase extends BaseUni
}
@Override
public Collection<ClassTransformer> getClassTransformers() {
return Collections.emptyList();
public ClassTransformer getClassTransformer() {
return null;
}
}

View File

@ -191,8 +191,8 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa
}
@Override
public Collection<ClassTransformer> getClassTransformers() {
return Collections.emptyList();
public ClassTransformer getClassTransformer() {
return null;
}
}

View File

@ -116,7 +116,7 @@ public class PersistenceUnitDescriptorAdapter implements PersistenceUnitDescript
}
@Override
public Collection<ClassTransformer> getClassTransformers() {
return Collections.emptyList();
public ClassTransformer getClassTransformer() {
return null;
}
}

View File

@ -271,8 +271,8 @@ public class EntityManagerFactoryBasedFunctionalTest
}
@Override
public Collection<ClassTransformer> getClassTransformers() {
return Collections.emptyList();
public ClassTransformer getClassTransformer() {
return null;
}
}