HHH-16952 Discover embeddable types through @Embedded annotation for enhancement in a pre-discovery phase
This commit is contained in:
parent
13bc7ff38c
commit
ea9a91502f
|
@ -341,13 +341,12 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
||||||
);
|
);
|
||||||
|
|
||||||
persistenceUnit.pushClassTransformer( enhancementContext );
|
persistenceUnit.pushClassTransformer( enhancementContext );
|
||||||
|
final ClassTransformer classTransformer = persistenceUnit.getClassTransformer();
|
||||||
if ( !persistenceUnit.getClassTransformers().isEmpty() ) {
|
if ( classTransformer != null ) {
|
||||||
final ClassLoader classLoader = persistenceUnit.getTempClassLoader();
|
final ClassLoader classLoader = persistenceUnit.getTempClassLoader();
|
||||||
if ( classLoader == null ) {
|
if ( classLoader == null ) {
|
||||||
throw persistenceException( "Enhancement requires a temp class loader, but none was given." );
|
throw persistenceException( "Enhancement requires a temp class loader, but none was given." );
|
||||||
}
|
}
|
||||||
for ( ClassTransformer classTransformer : persistenceUnit.getClassTransformers() ) {
|
|
||||||
for ( PersistentClass entityBinding : metadata.getEntityBindings() ) {
|
for ( PersistentClass entityBinding : metadata.getEntityBindings() ) {
|
||||||
if ( entityBinding.getClassName() != null ) {
|
if ( entityBinding.getClassName() != null ) {
|
||||||
classTransformer.discoverTypes( classLoader, entityBinding.getClassName() );
|
classTransformer.discoverTypes( classLoader, entityBinding.getClassName() );
|
||||||
|
@ -355,7 +354,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// for the time being we want to revoke access to the temp ClassLoader if one was passed
|
// for the time being we want to revoke access to the temp ClassLoader if one was passed
|
||||||
metamodelBuilder.applyTempClassLoader( null );
|
metamodelBuilder.applyTempClassLoader( null );
|
||||||
|
|
|
@ -194,7 +194,7 @@ public class ParsedPersistenceXmlDescriptor implements org.hibernate.jpa.boot.sp
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<ClassTransformer> getClassTransformers() {
|
public ClassTransformer getClassTransformer() {
|
||||||
return Collections.emptyList();
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import jakarta.persistence.PersistenceException;
|
||||||
import jakarta.persistence.SharedCacheMode;
|
import jakarta.persistence.SharedCacheMode;
|
||||||
import jakarta.persistence.ValidationMode;
|
import jakarta.persistence.ValidationMode;
|
||||||
import jakarta.persistence.spi.PersistenceUnitInfo;
|
import jakarta.persistence.spi.PersistenceUnitInfo;
|
||||||
|
@ -26,7 +28,7 @@ import org.hibernate.jpa.internal.enhance.EnhancingClassTransformerImpl;
|
||||||
*/
|
*/
|
||||||
public class PersistenceUnitInfoDescriptor implements PersistenceUnitDescriptor {
|
public class PersistenceUnitInfoDescriptor implements PersistenceUnitDescriptor {
|
||||||
private final PersistenceUnitInfo persistenceUnitInfo;
|
private final PersistenceUnitInfo persistenceUnitInfo;
|
||||||
private final ArrayList<ClassTransformer> classTransformers = new ArrayList<>();
|
private ClassTransformer classTransformer;
|
||||||
|
|
||||||
public PersistenceUnitInfoDescriptor(PersistenceUnitInfo persistenceUnitInfo) {
|
public PersistenceUnitInfoDescriptor(PersistenceUnitInfo persistenceUnitInfo) {
|
||||||
this.persistenceUnitInfo = persistenceUnitInfo;
|
this.persistenceUnitInfo = persistenceUnitInfo;
|
||||||
|
@ -114,16 +116,19 @@ public class PersistenceUnitInfoDescriptor implements PersistenceUnitDescriptor
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pushClassTransformer(EnhancementContext enhancementContext) {
|
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
|
// During testing, we will return a null temp class loader in cases where we don't care about enhancement
|
||||||
if ( persistenceUnitInfo.getNewTempClassLoader() != null ) {
|
if ( persistenceUnitInfo.getNewTempClassLoader() != null ) {
|
||||||
final EnhancingClassTransformerImpl classTransformer = new EnhancingClassTransformerImpl( enhancementContext );
|
final EnhancingClassTransformerImpl classTransformer = new EnhancingClassTransformerImpl( enhancementContext );
|
||||||
classTransformers.add( classTransformer );
|
this.classTransformer = classTransformer;
|
||||||
persistenceUnitInfo.addTransformer( classTransformer );
|
persistenceUnitInfo.addTransformer( classTransformer );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<ClassTransformer> getClassTransformers() {
|
public ClassTransformer getClassTransformer() {
|
||||||
return classTransformers;
|
return classTransformer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,5 +88,5 @@ public interface PersistenceUnitDescriptor {
|
||||||
|
|
||||||
void pushClassTransformer(EnhancementContext enhancementContext);
|
void pushClassTransformer(EnhancementContext enhancementContext);
|
||||||
|
|
||||||
Collection<ClassTransformer> getClassTransformers();
|
ClassTransformer getClassTransformer();
|
||||||
}
|
}
|
||||||
|
|
|
@ -253,8 +253,8 @@ public abstract class BaseJpaOrNativeBootstrapFunctionalTestCase extends BaseUni
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<ClassTransformer> getClassTransformers() {
|
public ClassTransformer getClassTransformer() {
|
||||||
return Collections.emptyList();
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -191,8 +191,8 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<ClassTransformer> getClassTransformers() {
|
public ClassTransformer getClassTransformer() {
|
||||||
return Collections.emptyList();
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ public class PersistenceUnitDescriptorAdapter implements PersistenceUnitDescript
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<ClassTransformer> getClassTransformers() {
|
public ClassTransformer getClassTransformer() {
|
||||||
return Collections.emptyList();
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,8 +271,8 @@ public class EntityManagerFactoryBasedFunctionalTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<ClassTransformer> getClassTransformers() {
|
public ClassTransformer getClassTransformer() {
|
||||||
return Collections.emptyList();
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue