HHH-7949 - Prevent lazy loading collections for bidirectional associations where not modified when withModifiedFlag is used.

This commit is contained in:
Chris Cranford 2016-12-04 15:07:55 -05:00
parent 1081c02c6b
commit 59870d0a14
1 changed files with 9 additions and 1 deletions

View File

@ -193,10 +193,18 @@ public abstract class AbstractCollectionMapper<T> implements PropertyMapper {
data.put( propertyData.getModifiedFlagPropertyName(), true );
}
else {
// HHH-7949 - Performance optimization to avoid lazy-fetching collections that have
// not been changed for deriving the modified flags value.
final PersistentCollection pc = (PersistentCollection) newObj;
if ( ( pc != null && !pc.isDirty() ) || ( newObj == null && oldObj == null ) ) {
data.put( propertyData.getModifiedFlagPropertyName(), false );
return;
}
final List<PersistentCollectionChangeData> changes = mapCollectionChanges(
session,
commonCollectionMapperData.getCollectionReferencingPropertyData().getName(),
(PersistentCollection) newObj,
pc,
(Serializable) oldObj,
null
);