@ Override public void merge ( final Object from , final Object target , final NullHandlingPolicy nullPolicy ) { if ( from == null || target == null ) { return ; } final BeanWrapper fromWrapper = beanWrapper ( from ) ; final BeanWrapper targetWrapper = beanWrapper ( target ) ; final DomainTypeAdministrationConfiguration domainTypeAdministrationConfiguration = configuration . forManagedDomainType ( target . getClass ( ) ) ; final PersistentEntity < ? , ? > entity = domainTypeAdministrationConfiguration . getPersistentEntity ( ) ; entity . doWithProperties ( new SimplePropertyHandler ( ) { @ Override public void doWithPersistentProperty ( PersistentProperty < ? > persistentProperty ) { Object sourceValue = fromWrapper . getPropertyValue ( persistentProperty . getName ( ) ) ; Object targetValue = targetWrapper . getPropertyValue ( persistentProperty . getName ( ) ) ; if ( entity . isIdProperty ( persistentProperty ) ) { return ; } if ( nullSafeEquals ( sourceValue , targetValue ) ) { return ; } if ( propertyIsHiddenInFormView ( persistentProperty , domainTypeAdministrationConfiguration ) ) { return ; } if ( nullPolicy == APPLY_NULLS || sourceValue != null ) { targetWrapper . setPropertyValue ( persistentProperty . getName ( ) , sourceValue ) ; } } } ) ; entity . doWithAssociations ( new SimpleAssociationHandler ( ) { @ Override @ SuppressWarnings ( "unchecked" ) public void doWithAssociation ( Association < ? extends PersistentProperty < ? > > association ) { PersistentProperty < ? > persistentProperty = association . getInverse ( ) ; Object fromValue = fromWrapper . getPropertyValue ( persistentProperty . getName ( ) ) ; Object targetValue = targetWrapper . getPropertyValue ( persistentProperty . getName ( ) ) ; if ( propertyIsHiddenInFormView ( persistentProperty , domainTypeAdministrationConfiguration ) ) { return ; } if ( ( fromValue == null && nullPolicy == APPLY_NULLS ) ) { targetWrapper . setPropertyValue ( persistentProperty . getName ( ) , fromValue ) ; } if ( persistentProperty . isCollectionLike ( ) ) { Collection < Object > sourceCollection = ( Collection ) fromValue ; Collection < Object > targetCollection = ( Collection ) targetValue ; Collection < Object > candidatesForAddition = candidatesForAddition ( sourceCollection , targetCollection , persistentProperty ) ; Collection < Object > candidatesForRemoval = candidatesForRemoval ( sourceCollection , targetCollection , persistentProperty ) ; removeReferencedItems ( targetCollection , candidatesForRemoval ) ; addReferencedItems ( targetCollection , candidatesForAddition ) ; return ; } if ( ! nullSafeEquals ( fromValue , targetWrapper . getPropertyValue ( persistentProperty . getName ( ) ) ) ) { targetWrapper . setPropertyValue ( persistentProperty . getName ( ) , fromValue ) ; } } } ) ; }
Merges the given target object into the source one .