diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/EntityEntry.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/EntityEntry.java index 0dea047098..e4c52dedce 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/EntityEntry.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/EntityEntry.java @@ -35,6 +35,7 @@ import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.UniqueKeyLoadable; import org.hibernate.pretty.MessageHelper; +import org.hibernate.service.instrumentation.spi.InstrumentationService; /** * We need an entry to tell us all about the current state of an object with respect to its persistent state @@ -256,8 +257,8 @@ public final class EntityEntry implements Serializable { public boolean requiresDirtyCheck(Object entity) { return isModifiableEntity() && ( getPersister().hasMutableProperties() || - !FieldInterceptionHelper.isInstrumented( entity ) || - FieldInterceptionHelper.extractFieldInterceptor( entity).isDirty() + !getPersister().getFactory().getServiceRegistry().getService( InstrumentationService.class ).isInstrumented(entity) || + FieldInterceptionHelper.extractFieldInterceptor(entity).isDirty() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java index 414fd2e816..da02b6e15a 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java @@ -42,6 +42,7 @@ import org.hibernate.engine.internal.Versioning; import org.hibernate.engine.spi.CascadingAction; import org.hibernate.engine.spi.EntityEntry; import org.hibernate.engine.spi.EntityKey; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.Status; import org.hibernate.event.spi.EventSource; @@ -50,6 +51,7 @@ import org.hibernate.id.IdentifierGeneratorHelper; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.pretty.MessageHelper; +import org.hibernate.service.instrumentation.spi.InstrumentationService; import org.hibernate.type.Type; import org.hibernate.type.TypeHelper; @@ -339,7 +341,10 @@ public abstract class AbstractSaveEventListener extends AbstractReassociateEvent } private void markInterceptorDirty(Object entity, EntityPersister persister, EventSource source) { - if ( FieldInterceptionHelper.isInstrumented( entity ) ) { + InstrumentationService instrumentationService = persister.getFactory() + .getServiceRegistry() + .getService( InstrumentationService.class ); + if ( instrumentationService.isInstrumented( entity ) ) { FieldInterceptor interceptor = FieldInterceptionHelper.injectFieldInterceptor( entity, persister.getEntityName(), diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java index fca17cd171..293b4819cf 100755 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java @@ -35,6 +35,7 @@ import org.hibernate.AssertionFailure; import org.hibernate.HibernateException; import org.hibernate.engine.internal.Cascade; import org.hibernate.engine.spi.EntityEntry; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.event.spi.EventSource; import org.hibernate.event.spi.MergeEvent; @@ -53,6 +54,7 @@ import org.hibernate.engine.spi.Status; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.LazyInitializer; +import org.hibernate.service.instrumentation.spi.InstrumentationService; import org.hibernate.type.ForeignKeyDirection; import org.hibernate.type.Type; import org.hibernate.type.TypeHelper; @@ -493,15 +495,18 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme copyValues(persister, entity, target, source, copyCache); //copyValues works by reflection, so explicitly mark the entity instance dirty - markInterceptorDirty( entity, target ); + markInterceptorDirty( entity, target, persister.getFactory() ); event.setResult(result); } } - private void markInterceptorDirty(final Object entity, final Object target) { - if ( FieldInterceptionHelper.isInstrumented( entity ) ) { + private void markInterceptorDirty(final Object entity, final Object target, SessionFactoryImplementor factory) { + InstrumentationService instrumentationService = factory + .getServiceRegistry() + .getService( InstrumentationService.class ); + if ( instrumentationService.isInstrumented( entity ) ) { FieldInterceptor interceptor = FieldInterceptionHelper.extractFieldInterceptor( target ); if ( interceptor != null ) { interceptor.dirty(); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index 5a52b411ed..796faa3f2c 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -104,6 +104,7 @@ import org.hibernate.metamodel.relational.DerivedValue; import org.hibernate.metamodel.relational.Value; import org.hibernate.pretty.MessageHelper; import org.hibernate.property.BackrefPropertyAccessor; +import org.hibernate.service.instrumentation.spi.InstrumentationService; import org.hibernate.sql.Alias; import org.hibernate.sql.Delete; import org.hibernate.sql.Insert; @@ -3943,7 +3944,10 @@ public abstract class AbstractEntityPersister public void afterReassociate(Object entity, SessionImplementor session) { //if ( hasLazyProperties() ) { - if ( FieldInterceptionHelper.isInstrumented( entity ) ) { + InstrumentationService instrumentationService = session.getFactory() + .getServiceRegistry() + .getService( InstrumentationService.class ); + if ( instrumentationService.isInstrumented( entity ) ) { FieldInterceptor interceptor = FieldInterceptionHelper.extractFieldInterceptor( entity ); if ( interceptor != null ) { interceptor.setSession( session ); diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java index a02b0a2ba3..a7cb0c0456 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java @@ -55,6 +55,7 @@ import org.hibernate.metamodel.binding.BasicAttributeBinding; import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.domain.Attribute; import org.hibernate.metamodel.domain.SingularAttribute; +import org.hibernate.service.instrumentation.spi.InstrumentationService; import org.hibernate.tuple.IdentifierProperty; import org.hibernate.tuple.PropertyFactory; import org.hibernate.tuple.StandardProperty; @@ -131,6 +132,7 @@ public class EntityMetamodel implements Serializable { private final EntityMode entityMode; private final EntityTuplizer entityTuplizer; + private boolean lazyAvailable; public EntityMetamodel(PersistentClass persistentClass, SessionFactoryImplementor sessionFactory) { this.sessionFactory = sessionFactory; @@ -146,8 +148,9 @@ public class EntityMetamodel implements Serializable { versioned = persistentClass.isVersioned(); - boolean lazyAvailable = persistentClass.hasPojoRepresentation() && - FieldInterceptionHelper.isInstrumented( persistentClass.getMappedClass() ); + InstrumentationService instrumentationService = sessionFactory.getServiceRegistry().getService( InstrumentationService.class ); + lazyAvailable = persistentClass.hasPojoRepresentation() && + instrumentationService.isInstrumented( persistentClass.getMappedClass() ); boolean hasLazy = false; propertySpan = persistentClass.getPropertyClosureSpan(); @@ -373,12 +376,14 @@ public class EntityMetamodel implements Serializable { boolean hasPojoRepresentation = false; Class mappedClass = null; Class proxyInterfaceClass = null; - boolean lazyAvailable = false; - if ( entityBinding.getEntity().getClassReferenceUnresolved() != null ) { + lazyAvailable = false; + if ( entityBinding.getEntity().getClassReferenceUnresolved() != null ) { hasPojoRepresentation = true; mappedClass = entityBinding.getEntity().getClassReference(); proxyInterfaceClass = entityBinding.getProxyInterfaceType().getValue(); - lazyAvailable = FieldInterceptionHelper.isInstrumented( mappedClass ); + InstrumentationService instrumentationService = sessionFactory.getServiceRegistry() + .getService( InstrumentationService.class ); + lazyAvailable = instrumentationService.isInstrumented( mappedClass ); } boolean hasLazy = false; @@ -935,4 +940,11 @@ public class EntityMetamodel implements Serializable { public EntityMode getEntityMode() { return entityMode; } + + /** + * Whether or not this class can be lazy (ie intercepted) + */ + public boolean isInstrumented() { + return lazyAvailable; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/PojoEntityTuplizer.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/PojoEntityTuplizer.java index 0ebd8b9810..8a005ca8ce 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/PojoEntityTuplizer.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/PojoEntityTuplizer.java @@ -76,12 +76,14 @@ public class PojoEntityTuplizer extends AbstractEntityTuplizer { private final boolean lifecycleImplementor; private final Set lazyPropertyNames = new HashSet(); private final ReflectionOptimizer optimizer; + private final boolean isInstrumented; public PojoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) { super( entityMetamodel, mappedEntity ); this.mappedClass = mappedEntity.getMappedClass(); this.proxyInterface = mappedEntity.getProxyInterface(); this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedClass ); + this.isInstrumented = entityMetamodel.isInstrumented(); Iterator iter = mappedEntity.getPropertyClosureIterator(); while ( iter.hasNext() ) { @@ -118,6 +120,7 @@ public class PojoEntityTuplizer extends AbstractEntityTuplizer { this.mappedClass = mappedEntity.getEntity().getClassReference(); this.proxyInterface = mappedEntity.getProxyInterfaceType().getValue(); this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedClass ); + this.isInstrumented = entityMetamodel.isInstrumented(); for ( AttributeBinding property : mappedEntity.getAttributeBindingClosure() ) { if ( property.isLazy() ) { @@ -520,7 +523,7 @@ public class PojoEntityTuplizer extends AbstractEntityTuplizer { * {@inheritDoc} */ public boolean isInstrumented() { - return FieldInterceptionHelper.isInstrumented( getMappedClass() ); + return isInstrumented; } /**