mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-06 19:36:03 +00:00
HHH-10252 - Trigger the lazy loading of cascading attributes (5.0)
This commit is contained in:
parent
5e33aacd01
commit
7a20fed92b
@ -62,12 +62,21 @@ public LazyAttributeLoader(SessionImplementor session, Set<String> lazyFields, S
|
||||
|
||||
protected final Object intercept(Object target, String attributeName, Object value) {
|
||||
if ( !isAttributeLoaded( attributeName ) ) {
|
||||
return loadAttribute( target, attributeName );
|
||||
Object loadedValue = fetchAttribute( target, attributeName );
|
||||
setLoaded( attributeName );
|
||||
return loadedValue;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private Object loadAttribute(final Object target, final String attributeName) {
|
||||
/**
|
||||
* Fetches the lazy attribute. The attribute does not get associated with the entity. (To be used by hibernate methods)
|
||||
*/
|
||||
public Object fetchAttribute(final Object target, final String attributeName) {
|
||||
return loadAttribute( target, attributeName );
|
||||
}
|
||||
|
||||
protected Object loadAttribute(final Object target, final String attributeName) {
|
||||
return new Helper( this ).performWork(
|
||||
new LazyInitializationWork() {
|
||||
@Override
|
||||
@ -167,6 +176,7 @@ private void takeCollectionSizeSnapshot(Object target, String fieldName, Object
|
||||
CollectionTracker tracker = ( (SelfDirtinessTracker) target ).$$_hibernate_getCollectionTracker();
|
||||
if ( tracker == null ) {
|
||||
( (SelfDirtinessTracker) target ).$$_hibernate_clearDirtyAttributes();
|
||||
tracker = ( (SelfDirtinessTracker) target ).$$_hibernate_getCollectionTracker();
|
||||
}
|
||||
tracker.add( fieldName, ( (Collection) value ).size() );
|
||||
}
|
||||
|
@ -12,11 +12,13 @@
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoader;
|
||||
import org.hibernate.collection.spi.PersistentCollection;
|
||||
import org.hibernate.engine.spi.CascadeStyle;
|
||||
import org.hibernate.engine.spi.CascadingAction;
|
||||
import org.hibernate.engine.spi.CollectionEntry;
|
||||
import org.hibernate.engine.spi.EntityEntry;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||
import org.hibernate.engine.spi.Status;
|
||||
import org.hibernate.event.spi.EventSource;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
@ -87,19 +89,32 @@ public static void cascade(
|
||||
for ( int i = 0; i < types.length; i++) {
|
||||
final CascadeStyle style = cascadeStyles[i];
|
||||
final String propertyName = propertyNames[i];
|
||||
if ( hasUninitializedLazyProperties && persister.getPropertyLaziness()[i] && ! action.performOnLazyProperty() ) {
|
||||
//do nothing to avoid a lazy property initialization
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( style.doCascade( action ) ) {
|
||||
Object child;
|
||||
|
||||
// For bytecode enhanced entities, need to fetch the attribute
|
||||
boolean lazy = hasUninitializedLazyProperties && persister.getPropertyLaziness()[i] && action.performOnLazyProperty();
|
||||
if ( lazy && parent instanceof PersistentAttributeInterceptable ) {
|
||||
Object interceptor = ( (PersistentAttributeInterceptable) parent ).$$_hibernate_getInterceptor();
|
||||
if ( interceptor instanceof LazyAttributeLoader ) {
|
||||
child = ( (LazyAttributeLoader) interceptor ).fetchAttribute( parent, propertyName );
|
||||
}
|
||||
else {
|
||||
child = null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
child = persister.getPropertyValue( parent, i );
|
||||
}
|
||||
|
||||
cascadeProperty(
|
||||
action,
|
||||
cascadePoint,
|
||||
eventSource,
|
||||
componentPathStackDepth,
|
||||
parent,
|
||||
persister.getPropertyValue( parent, i ),
|
||||
child,
|
||||
types[i],
|
||||
style,
|
||||
propertyName,
|
||||
|
Loading…
x
Reference in New Issue
Block a user