HHH-14290 Remove capability of loading classes by name from HCANN

This commit is contained in:
Sanne Grinovero 2020-10-21 23:34:45 +01:00
parent 5744d546ac
commit 9ed86fd363
16 changed files with 152 additions and 199 deletions

View File

@ -13,11 +13,8 @@ import java.util.HashMap;
import java.util.Map;
import org.hibernate.AssertionFailure;
import org.hibernate.annotations.common.reflection.ClassLoaderDelegate;
import org.hibernate.annotations.common.reflection.ClassLoadingException;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.annotations.common.reflection.java.JavaReflectionManager;
import org.hibernate.annotations.common.util.StandardClassLoaderDelegateImpl;
import org.hibernate.boot.AttributeConverterInfo;
import org.hibernate.boot.CacheRegionDefinition;
import org.hibernate.boot.archive.scan.internal.StandardScanOptions;
@ -313,32 +310,7 @@ public class BootstrapContextImpl implements BootstrapContext {
private JavaReflectionManager generateHcannReflectionManager() {
final JavaReflectionManager reflectionManager = new JavaReflectionManager();
reflectionManager.setMetadataProvider( new JPAMetadataProvider( this ) );
reflectionManager.injectClassLoaderDelegate( generateHcannClassLoaderDelegate() );
return reflectionManager;
}
private ClassLoaderDelegate generateHcannClassLoaderDelegate() {
// class loading here needs to be drastically different for 7.0
// but luckily 7.0 will do away with HCANN use and be easier to
// implement this.
//
// todo (6.0) : *if possible* make similar change in 6.0
// possibly using the JPA temp class loader or create our own "throw awy" ClassLoader;
// the trouble there is that we eventually need to load the Class into the real
// ClassLoader prior to use
final ClassLoaderService classLoaderService = getServiceRegistry().getService( ClassLoaderService.class );
return new ClassLoaderDelegate() {
@Override
public <T> Class<T> classForName(String className) throws ClassLoadingException {
try {
return classLoaderService.classForName( className );
}
catch (org.hibernate.boot.registry.classloading.spi.ClassLoadingException e) {
return StandardClassLoaderDelegateImpl.INSTANCE.classForName( className );
}
}
};
}
}

View File

@ -17,8 +17,6 @@ import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.MappedSuperclass;
import org.hibernate.AnnotationException;
import org.hibernate.annotations.common.reflection.ClassLoadingException;
import org.hibernate.annotations.common.reflection.MetadataProviderInjector;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.annotations.common.reflection.XClass;
@ -59,6 +57,7 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc
private final LinkedHashSet<String> annotatedPackages = new LinkedHashSet<String>();
private final List<XClass> xClasses = new ArrayList<XClass>();
private final ClassLoaderService classLoaderService;
public AnnotationMetadataSourceProcessorImpl(
ManagedResources managedResources,
@ -74,6 +73,7 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc
}
final AttributeConverterManager attributeConverterManager = new AttributeConverterManager( rootMetadataBuildingContext );
this.classLoaderService = rootMetadataBuildingContext.getBuildingOptions().getServiceRegistry().getService( ClassLoaderService.class );
if ( rootMetadataBuildingContext.getBuildingOptions().isXmlMappingEnabled() ) {
@ -97,25 +97,24 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc
final List<String> classNames = jpaMetadataProvider.getXMLContext().addDocument( dom4jDocument );
for ( String className : classNames ) {
xClasses.add( toXClass( className, reflectionManager ) );
xClasses.add( toXClass( className, reflectionManager, classLoaderService ) );
}
}
jpaMetadataProvider.getXMLContext().applyDiscoveredAttributeConverters( attributeConverterManager );
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
final ClassLoaderService cls = rootMetadataBuildingContext.getBuildingOptions().getServiceRegistry().getService( ClassLoaderService.class );
for ( String className : managedResources.getAnnotatedClassNames() ) {
final Class annotatedClass = cls.classForName( className );
categorizeAnnotatedClass( annotatedClass, attributeConverterManager );
final Class annotatedClass = classLoaderService.classForName( className );
categorizeAnnotatedClass( annotatedClass, attributeConverterManager, classLoaderService );
}
for ( Class annotatedClass : managedResources.getAnnotatedClassReferences() ) {
categorizeAnnotatedClass( annotatedClass, attributeConverterManager );
categorizeAnnotatedClass( annotatedClass, attributeConverterManager, classLoaderService );
}
}
private void categorizeAnnotatedClass(Class annotatedClass, AttributeConverterManager attributeConverterManager) {
private void categorizeAnnotatedClass(Class annotatedClass, AttributeConverterManager attributeConverterManager, ClassLoaderService cls) {
final XClass xClass = reflectionManager.toXClass( annotatedClass );
// categorize it, based on assumption it does not fall into multiple categories
if ( xClass.isAnnotationPresent( Converter.class ) ) {
@ -135,13 +134,8 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc
}
@SuppressWarnings("deprecation")
private XClass toXClass(String className, ReflectionManager reflectionManager) {
try {
return reflectionManager.classForName( className );
}
catch ( ClassLoadingException e ) {
throw new AnnotationException( "Unable to load class defined in XML: " + className, e );
}
private XClass toXClass(String className, ReflectionManager reflectionManager, ClassLoaderService cls) {
return reflectionManager.toXClass( cls.classForName( className ) );
}
// private Document toDom4jDocument(MappingBinder.DelayedOrmXmlData delayedOrmXmlData) {
@ -192,7 +186,7 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc
AnnotationBinder.bindDefaults( rootMetadataBuildingContext );
for ( String annotatedPackage : annotatedPackages ) {
AnnotationBinder.bindPackage( annotatedPackage, rootMetadataBuildingContext );
AnnotationBinder.bindPackage( classLoaderService, annotatedPackage, rootMetadataBuildingContext );
}
}
@ -303,7 +297,7 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc
@Override
public void postProcessEntityHierarchies() {
for ( String annotatedPackage : annotatedPackages ) {
AnnotationBinder.bindFetchProfilesForPackage( annotatedPackage, rootMetadataBuildingContext );
AnnotationBinder.bindFetchProfilesForPackage( classLoaderService, annotatedPackage, rootMetadataBuildingContext );
}
}

View File

@ -261,6 +261,22 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
);
}
@Override
public Package packageForNameOrNull(String packageName) {
try {
Class<?> aClass = Class.forName( packageName + ".package-info", true, getAggregatedClassLoader() );
return aClass == null ? null : aClass.getPackage();
}
catch (ClassNotFoundException e) {
log.packageNotFound( packageName );
return null;
}
catch (LinkageError e) {
log.warn( "LinkageError while attempting to load Package named " + packageName, e );
return null;
}
}
@Override
public <T> T workWithClassLoader(Work<T> work) {
return work.doWork( getAggregatedClassLoader() );

View File

@ -75,6 +75,21 @@ public interface ClassLoaderService extends Service, Stoppable {
<T> T generateProxy(InvocationHandler handler, Class... interfaces);
/**
* Loading a Package from the classloader. In case it's not found or an
* internal error (such as @see {@link LinkageError} occurs, we
* return null rather than throwing an exception.
* This is significantly different than loading a Class, as in all
* currently known usages, being unable to load the Package will
* only result in ignoring annotations on it - which is totally
* fine when the object doesn't exist.
* In case of other errors, implementations are expected to log
* a warning but it's still not treated as a fatal error.
* @param packageName
* @return the matching Package, or null.
*/
Package packageForNameOrNull(String packageName);
interface Work<T> {
T doWork(ClassLoader classLoader);
}

View File

@ -123,7 +123,7 @@ import org.hibernate.annotations.Tuplizers;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.annotations.Where;
import org.hibernate.annotations.common.reflection.ClassLoadingException;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.annotations.common.reflection.XAnnotatedElement;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.XMethod;
@ -132,6 +132,7 @@ import org.hibernate.annotations.common.reflection.XProperty;
import org.hibernate.boot.model.IdGeneratorStrategyInterpreter;
import org.hibernate.boot.model.IdentifierGeneratorDefinition;
import org.hibernate.boot.model.TypeDefinition;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.spi.InFlightMetadataCollector;
import org.hibernate.boot.spi.InFlightMetadataCollector.EntityTableXref;
import org.hibernate.boot.spi.MetadataBuildingContext;
@ -304,19 +305,12 @@ public final class AnnotationBinder {
}
}
public static void bindPackage(String packageName, MetadataBuildingContext context) {
XPackage pckg;
try {
pckg = context.getBootstrapContext().getReflectionManager().packageForName( packageName );
}
catch (ClassLoadingException e) {
LOG.packageNotFound( packageName );
return;
}
catch ( ClassNotFoundException cnf ) {
LOG.packageNotFound( packageName );
public static void bindPackage(ClassLoaderService cls, String packageName, MetadataBuildingContext context) {
final Package packaze = cls.packageForNameOrNull( packageName );
if ( packaze == null ) {
return;
}
final XPackage pckg = context.getBootstrapContext().getReflectionManager().toXPackage( packaze );
if ( pckg.isAnnotationPresent( SequenceGenerator.class ) ) {
SequenceGenerator ann = pckg.getAnnotation( SequenceGenerator.class );
@ -1419,20 +1413,13 @@ public final class AnnotationBinder {
bindFetchProfiles( clazzToProcess, context );
}
public static void bindFetchProfilesForPackage(String packageName, MetadataBuildingContext context) {
XPackage pckg;
try {
pckg = context.getBootstrapContext().getReflectionManager().packageForName( packageName );
}
catch (ClassLoadingException e) {
LOG.packageNotFound( packageName );
public static void bindFetchProfilesForPackage(ClassLoaderService cls, String packageName, MetadataBuildingContext context) {
final Package packaze = cls.packageForNameOrNull( packageName );
if ( packaze == null ) {
return;
}
catch ( ClassNotFoundException cnf ) {
LOG.packageNotFound( packageName );
return;
}
final ReflectionManager reflectionManager = context.getBootstrapContext().getReflectionManager();
final XPackage pckg = reflectionManager.toXPackage( packaze );
bindFetchProfiles( pckg, context );
}

View File

@ -31,7 +31,6 @@ import org.hibernate.annotations.AnyMetaDef;
import org.hibernate.annotations.AnyMetaDefs;
import org.hibernate.annotations.MetaValue;
import org.hibernate.annotations.SqlFragmentAlias;
import org.hibernate.annotations.common.reflection.ClassLoadingException;
import org.hibernate.annotations.common.reflection.XAnnotatedElement;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.XPackage;
@ -1097,14 +1096,8 @@ public class BinderHelper {
PropertyHolder propertyHolder,
String propertyName,
MetadataBuildingContext buildingContext) {
final XClass persistentXClass;
try {
persistentXClass = buildingContext.getBootstrapContext().getReflectionManager()
.classForName( propertyHolder.getPersistentClass().getClassName() );
}
catch ( ClassLoadingException e ) {
throw new AssertionFailure( "PersistentClass name cannot be converted into a Class", e);
}
final XClass persistentXClass = buildingContext.getBootstrapContext().getReflectionManager()
.toXClass( propertyHolder.getPersistentClass().getMappedClass() );
if ( propertyHolder.isInIdClass() ) {
PropertyData pd = buildingContext.getMetadataCollector().getPropertyAnnotatedWithIdAndToOne(
persistentXClass,

View File

@ -23,9 +23,9 @@ import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
import org.hibernate.FetchMode;
import org.hibernate.MappingException;
import org.hibernate.annotations.common.reflection.ClassLoadingException;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.XProperty;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.cfg.AccessType;
import org.hibernate.cfg.AnnotatedClassType;
@ -217,19 +217,17 @@ public class MapBinder extends CollectionBinder {
//does not make sense for a map key element.setIgnoreNotFound( ignoreNotFound );
}
else {
XClass keyXClass;
final XClass keyXClass;
AnnotatedClassType classType;
if ( BinderHelper.PRIMITIVE_NAMES.contains( mapKeyType ) ) {
classType = AnnotatedClassType.NONE;
keyXClass = null;
}
else {
try {
keyXClass = buildingContext.getBootstrapContext().getReflectionManager().classForName( mapKeyType );
}
catch (ClassLoadingException e) {
throw new AnnotationException( "Unable to find class: " + mapKeyType, e );
}
final BootstrapContext bootstrapContext = buildingContext.getBootstrapContext();
final Class<Object> mapKeyClass = bootstrapContext.getClassLoaderAccess().classForName( mapKeyType );
keyXClass = bootstrapContext.getReflectionManager().toXClass( mapKeyClass );
classType = buildingContext.getMetadataCollector().getClassType( keyXClass );
// force in case of attribute override naming the key
if ( isEmbedded || mappingDefinedAttributeOverrideOnMapKey( property ) ) {

View File

@ -26,7 +26,6 @@ import org.hibernate.annotations.MapKeyType;
import org.hibernate.annotations.Nationalized;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.common.reflection.ClassLoadingException;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.XProperty;
import org.hibernate.boot.model.TypeDefinition;
@ -534,27 +533,22 @@ public class SimpleValueBinder {
if ( simpleValue.getTypeName() != null && simpleValue.getTypeName().length() > 0
&& simpleValue.getMetadata().getTypeResolver().basic( simpleValue.getTypeName() ) == null ) {
try {
Class typeClass = buildingContext.getBootstrapContext().getClassLoaderAccess().classForName( simpleValue.getTypeName() );
Class typeClass = buildingContext.getBootstrapContext().getClassLoaderAccess().classForName( simpleValue.getTypeName() );
if ( typeClass != null && DynamicParameterizedType.class.isAssignableFrom( typeClass ) ) {
Properties parameters = simpleValue.getTypeParameters();
if ( parameters == null ) {
parameters = new Properties();
}
parameters.put( DynamicParameterizedType.IS_DYNAMIC, Boolean.toString( true ) );
parameters.put( DynamicParameterizedType.RETURNED_CLASS, returnedClassName );
parameters.put( DynamicParameterizedType.IS_PRIMARY_KEY, Boolean.toString( key ) );
parameters.put( DynamicParameterizedType.ENTITY, persistentClassName );
parameters.put( DynamicParameterizedType.XPROPERTY, xproperty );
parameters.put( DynamicParameterizedType.PROPERTY, xproperty.getName() );
parameters.put( DynamicParameterizedType.ACCESS_TYPE, accessType.getType() );
simpleValue.setTypeParameters( parameters );
if ( typeClass != null && DynamicParameterizedType.class.isAssignableFrom( typeClass ) ) {
Properties parameters = simpleValue.getTypeParameters();
if ( parameters == null ) {
parameters = new Properties();
}
}
catch (ClassLoadingException e) {
throw new MappingException( "Could not determine type for: " + simpleValue.getTypeName(), e );
parameters.put( DynamicParameterizedType.IS_DYNAMIC, Boolean.toString( true ) );
parameters.put( DynamicParameterizedType.RETURNED_CLASS, returnedClassName );
parameters.put( DynamicParameterizedType.IS_PRIMARY_KEY, Boolean.toString( key ) );
parameters.put( DynamicParameterizedType.ENTITY, persistentClassName );
parameters.put( DynamicParameterizedType.XPROPERTY, xproperty );
parameters.put( DynamicParameterizedType.PROPERTY, xproperty.getName() );
parameters.put( DynamicParameterizedType.ACCESS_TYPE, accessType.getType() );
simpleValue.setTypeParameters( parameters );
}
}

View File

@ -143,7 +143,8 @@ public class EventListenerRegistryImpl implements EventListenerRegistry, Stoppab
// we can have non java class persisted by hibernate
continue;
}
callbackBuilder.buildCallbacksForEntity( persistentClass.getClassName(), callbackRegistry );
final Class mappedClass = persistentClass.getMappedClass();
callbackBuilder.buildCallbacksForEntity( mappedClass, callbackRegistry );
for ( Iterator propertyIterator = persistentClass.getDeclaredPropertyIterator();
propertyIterator.hasNext(); ) {
@ -152,7 +153,7 @@ public class EventListenerRegistryImpl implements EventListenerRegistry, Stoppab
if ( property.getType().isComponentType() ) {
callbackBuilder.buildCallbacksForEmbeddable(
property,
persistentClass.getClassName(),
mappedClass,
callbackRegistry
);
}

View File

@ -20,7 +20,6 @@ import javax.persistence.MappedSuperclass;
import javax.persistence.PersistenceException;
import org.hibernate.MappingException;
import org.hibernate.annotations.common.reflection.ClassLoadingException;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.XMethod;
@ -52,53 +51,38 @@ final class CallbackBuilderLegacyImpl implements CallbackBuilder {
}
@Override
public void buildCallbacksForEntity(String entityClassName, CallbackRegistrar callbackRegistrar) {
try {
final XClass entityXClass = reflectionManager.classForName( entityClassName );
final Class entityClass = reflectionManager.toClass( entityXClass );
for ( CallbackType callbackType : CallbackType.values() ) {
if ( callbackRegistrar.hasRegisteredCallbacks( entityClass, callbackType ) ) {
// this most likely means we have a class mapped multiple times using the hbm.xml
// "entity name" feature
if ( log.isDebugEnabled() ) {
log.debugf(
"CallbackRegistry reported that Class [%s] already had %s callbacks registered; " +
"assuming this means the class was mapped twice " +
"(using hbm.xml entity-name support) - skipping subsequent registrations",
entityClassName,
callbackType.getCallbackAnnotation().getSimpleName()
);
}
continue;
public void buildCallbacksForEntity(Class entityClass, CallbackRegistrar callbackRegistrar) {
for ( CallbackType callbackType : CallbackType.values() ) {
if ( callbackRegistrar.hasRegisteredCallbacks( entityClass, callbackType ) ) {
// this most likely means we have a class mapped multiple times using the hbm.xml
// "entity name" feature
if ( log.isDebugEnabled() ) {
log.debugf(
"CallbackRegistry reported that Class [%s] already had %s callbacks registered; " +
"assuming this means the class was mapped twice " +
"(using hbm.xml entity-name support) - skipping subsequent registrations",
entityClass.getName(),
callbackType.getCallbackAnnotation().getSimpleName()
);
}
final Callback[] callbacks = resolveEntityCallbacks( entityXClass, callbackType, reflectionManager );
callbackRegistrar.registerCallbacks( entityClass, callbacks );
continue;
}
}
catch (ClassLoadingException e) {
throw new MappingException( "entity class not found: " + entityClassName, e );
final Callback[] callbacks = resolveEntityCallbacks( entityClass, callbackType, reflectionManager );
callbackRegistrar.registerCallbacks( entityClass, callbacks );
}
}
@Override
public void buildCallbacksForEmbeddable(
Property embeddableProperty, String entityClassName, CallbackRegistrar callbackRegistrar) {
try {
final XClass entityXClass = reflectionManager.classForName( entityClassName );
final Class entityClass = reflectionManager.toClass( entityXClass );
for ( CallbackType callbackType : CallbackType.values() ) {
final Callback[] callbacks = resolveEmbeddableCallbacks(
entityClass,
embeddableProperty,
callbackType,
reflectionManager
);
callbackRegistrar.registerCallbacks( entityClass, callbacks );
}
}
catch (ClassLoadingException e) {
throw new MappingException( "Class not found: ", e );
Property embeddableProperty, Class entityClass, CallbackRegistrar callbackRegistrar) {
for ( CallbackType callbackType : CallbackType.values() ) {
final Callback[] callbacks = resolveEmbeddableCallbacks(
entityClass,
embeddableProperty,
callbackType,
reflectionManager
);
callbackRegistrar.registerCallbacks( entityClass, callbacks );
}
}
@ -108,11 +92,11 @@ final class CallbackBuilderLegacyImpl implements CallbackBuilder {
}
@SuppressWarnings({"unchecked", "WeakerAccess"})
public Callback[] resolveEntityCallbacks(XClass beanClass, CallbackType callbackType, ReflectionManager reflectionManager) {
public Callback[] resolveEntityCallbacks(Class entityClass, CallbackType callbackType, ReflectionManager reflectionManager) {
List<Callback> callbacks = new ArrayList<>();
List<String> callbacksMethodNames = new ArrayList<>();
List<Class> orderedListeners = new ArrayList<>();
XClass currentClazz = beanClass;
XClass currentClazz = reflectionManager.toXClass( entityClass );
boolean stopListeners = false;
boolean stopDefaultListeners = false;
do {
@ -140,7 +124,7 @@ final class CallbackBuilderLegacyImpl implements CallbackBuilder {
"Adding %s as %s callback for entity %s",
methodName,
callbackType.getCallbackAnnotation().getSimpleName(),
beanClass.getName()
entityClass.getName()
);
}
callbacks.add( 0, callback ); //superclass first
@ -149,7 +133,7 @@ final class CallbackBuilderLegacyImpl implements CallbackBuilder {
else {
throw new PersistenceException(
"You can only annotate one callback method with "
+ callbackType.getCallbackAnnotation().getName() + " in bean class: " + beanClass.getName()
+ callbackType.getCallbackAnnotation().getName() + " in bean class: " + entityClass.getName()
);
}
}
@ -216,7 +200,7 @@ final class CallbackBuilderLegacyImpl implements CallbackBuilder {
"Adding %s as %s callback for entity %s",
methodName,
callbackType.getCallbackAnnotation().getSimpleName(),
beanClass.getName()
entityClass.getName()
);
}
callbacks.add( 0, callback ); // listeners first
@ -225,7 +209,7 @@ final class CallbackBuilderLegacyImpl implements CallbackBuilder {
throw new PersistenceException(
"You can only annotate one callback method with "
+ callbackType.getCallbackAnnotation().getName()
+ " in bean class: " + beanClass.getName()
+ " in bean class: " + entityClass.getName()
+ " and callback listener: " + listener.getName()
);
}
@ -240,8 +224,8 @@ final class CallbackBuilderLegacyImpl implements CallbackBuilder {
@SuppressWarnings({"unchecked", "WeakerAccess"})
public Callback[] resolveEmbeddableCallbacks(Class entityClass, Property embeddableProperty, CallbackType callbackType, ReflectionManager reflectionManager) {
final String embeddableClassName = embeddableProperty.getType().getReturnedClass().getName();
final XClass embeddableXClass = reflectionManager.classForName( embeddableClassName );
final Class embeddableClass = embeddableProperty.getType().getReturnedClass();
final XClass embeddableXClass = reflectionManager.toXClass( embeddableClass );
final Getter embeddableGetter = embeddableProperty.getGetter( entityClass );
final List<Callback> callbacks = new ArrayList<>();
final List<String> callbacksMethodNames = new ArrayList<>();

View File

@ -12,12 +12,12 @@ import org.hibernate.mapping.Property;
final class EmptyCallbackBuilder implements CallbackBuilder {
@Override
public void buildCallbacksForEntity(String entityClassName, CallbackRegistrar callbackRegistrar) {
public void buildCallbacksForEntity(Class entityClass, CallbackRegistrar callbackRegistrar) {
//no-op
}
@Override
public void buildCallbacksForEmbeddable(Property embeddableProperty, String entityClassName, CallbackRegistrar callbackRegistrar) {
public void buildCallbacksForEmbeddable(Property embeddableProperty, Class entityClass, CallbackRegistrar callbackRegistrar) {
//no-op
}

View File

@ -28,11 +28,11 @@ public interface CallbackBuilder {
void registerCallbacks(Class entityClass, Callback[] callbacks);
}
void buildCallbacksForEntity(String entityClassName, CallbackRegistrar callbackRegistrar);
void buildCallbacksForEntity(Class entityClass, CallbackRegistrar callbackRegistrar);
void buildCallbacksForEmbeddable(
Property embeddableProperty,
String entityClassName,
Class entityClass,
CallbackRegistrar callbackRegistrar);
void release();

View File

@ -11,7 +11,6 @@ import java.util.Set;
import javax.persistence.Column;
import org.hibernate.MappingException;
import org.hibernate.annotations.common.reflection.ClassLoadingException;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.XProperty;
@ -310,14 +309,7 @@ public class RevisionInfoConfiguration {
for ( PersistentClass persistentClass : metadata.getEntityBindings() ) {
// Ensure we're in POJO, not dynamic model, mapping.
if (persistentClass.getClassName() != null) {
XClass clazz;
try {
clazz = reflectionManager.classForName( persistentClass.getClassName() );
}
catch (ClassLoadingException e) {
throw new MappingException( e );
}
XClass clazz = reflectionManager.toXClass( persistentClass.getMappedClass() );
final RevisionEntity revisionEntity = clazz.getAnnotation( RevisionEntity.class );
if ( revisionEntity != null ) {
if (revisionEntityFound) {

View File

@ -22,6 +22,7 @@ import javax.persistence.JoinColumn;
import org.dom4j.Element;
import org.hibernate.MappingException;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.envers.ModificationStore;
import org.hibernate.envers.RelationTargetAuditMode;
import org.hibernate.envers.configuration.internal.metadata.reader.AuditedPropertiesReader;
@ -658,9 +659,12 @@ public final class CollectionMetadataGenerator {
.getMetadataBuildingOptions()
.getReflectionManager();
final ClassLoaderService classLoaderService = mainGenerator.getGlobalCfg()
.getEnversService()
.getClassLoaderService();
new ComponentAuditedPropertiesReader(
ModificationStore.FULL,
new AuditedPropertiesReader.ComponentPropertiesSource( reflectionManager, component ),
new AuditedPropertiesReader.ComponentPropertiesSource( classLoaderService, reflectionManager, component ),
auditData, mainGenerator.getGlobalCfg(), reflectionManager, ""
).read();

View File

@ -7,7 +7,6 @@
package org.hibernate.envers.configuration.internal.metadata.reader;
import org.hibernate.MappingException;
import org.hibernate.annotations.common.reflection.ClassLoadingException;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.envers.AuditTable;
@ -96,30 +95,25 @@ public final class AnnotationsMetadataReader {
return auditData;
}
try {
final XClass xclass = reflectionManager.classForName( pc.getClassName() );
final XClass xclass = reflectionManager.toXClass( pc.getMappedClass() );
final ModificationStore defaultStore = getDefaultAudited( xclass );
if ( defaultStore != null ) {
auditData.setDefaultAudited( true );
}
new AuditedPropertiesReader(
defaultStore,
new PersistentClassPropertiesSource( xclass ),
auditData,
globalCfg,
reflectionManager,
""
).read();
addAuditTable( xclass );
addAuditSecondaryTables( xclass );
}
catch (ClassLoadingException e) {
throw new MappingException( e );
final ModificationStore defaultStore = getDefaultAudited( xclass );
if ( defaultStore != null ) {
auditData.setDefaultAudited( true );
}
new AuditedPropertiesReader(
defaultStore,
new PersistentClassPropertiesSource( xclass ),
auditData,
globalCfg,
reflectionManager,
""
).read();
addAuditTable( xclass );
addAuditSecondaryTables( xclass );
return auditData;
}

View File

@ -25,10 +25,11 @@ import javax.persistence.Version;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.annotations.common.reflection.ClassLoadingException;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.XProperty;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.envers.AuditJoinTable;
import org.hibernate.envers.AuditMappedBy;
import org.hibernate.envers.AuditOverride;
@ -432,8 +433,10 @@ public class AuditedPropertiesReader {
// Marking component properties as placed directly in class (not inside another component).
componentData.setBeanName( null );
final ClassLoaderService classLoaderService = globalCfg.getEnversService().getClassLoaderService();
final PersistentPropertiesSource componentPropertiesSource = new ComponentPropertiesSource(
reflectionManager,
classLoaderService, reflectionManager,
propertyValue
);
final AuditedPropertiesReader audPropReader = new AuditedPropertiesReader(
@ -459,7 +462,10 @@ public class AuditedPropertiesReader {
componentPropertiesSource = new DynamicComponentSource( reflectionManager, propertyValue, property );
}
else {
componentPropertiesSource = new ComponentPropertiesSource( reflectionManager, propertyValue );
final ClassLoaderService classLoaderService = this.globalCfg.getEnversService().getClassLoaderService();
componentPropertiesSource = new ComponentPropertiesSource(
classLoaderService,
reflectionManager, propertyValue );
}
final ComponentAuditedPropertiesReader audPropReader = new ComponentAuditedPropertiesReader(
@ -786,14 +792,17 @@ public class AuditedPropertiesReader {
this.component = component;
}
public ComponentPropertiesSource(ReflectionManager reflectionManager, Component component) {
public ComponentPropertiesSource(
ClassLoaderService classLoaderService,
ReflectionManager reflectionManager,
Component component) {
try {
this.xclass = reflectionManager.classForName( component.getComponentClassName() );
Class<Object> objectClass = classLoaderService.classForName( component.getComponentClassName() );
this.xclass = reflectionManager.toXClass( objectClass );
}
catch ( ClassLoadingException e ) {
throw new MappingException( e );
}
this.component = component;
}