private void setFKField(Object targetObject, ClassDescriptor cld, ObjectReferenceDescriptor rds, Object referencedObject)
    {
        ValueContainer[] refPkValues;
        FieldDescriptor fld;
        FieldDescriptor[] objFkFields = rds.getForeignKeyFieldDescriptors(cld);
        if (objFkFields == null)
        {
            throw new PersistenceBrokerException("No foreign key fields defined for class '"+cld.getClassNameOfObject()+"'");
        }
        if(referencedObject == null)
        {
            refPkValues = null;
        }
        else
        {
            Class refClass = proxyFactory.getRealClass(referencedObject);
            ClassDescriptor refCld = getClassDescriptor(refClass);
            refPkValues = brokerHelper.getKeyValues(refCld, referencedObject, false);
        }
        for (int i = 0; i < objFkFields.length; i++)
        {
            fld = objFkFields[i];
            /*
            arminw:
            we set the FK value when the extracted PK fields from the referenced object are not null at all
            or if null, the FK field was not a PK field of target object too.
            Should be ok, because the values of the extracted PK field values should never be null and never
            change, so it doesn't matter if the target field is a PK too.
            */
            if(refPkValues != null || !fld.isPrimaryKey())
            {
                fld.getPersistentField().set(targetObject, refPkValues != null ? refPkValues[i].getValue(): null);
            }
        }
    }
private void setFKField ( Object targetObject , ClassDescriptor cld , ObjectReferenceDescriptor rds , Object referencedObject ) { ValueContainer [ ] refPkValues ; FieldDescriptor fld ; FieldDescriptor [ ] objFkFields = rds . getForeignKeyFieldDescriptors ( cld ) ; if ( objFkFields == null ) { throw new PersistenceBrokerException ( "No foreign key fields defined for class '" + cld . getClassNameOfObject ( ) + "'" ) ; } if ( referencedObject == null ) { refPkValues = null ; } else { Class refClass = proxyFactory . getRealClass ( referencedObject ) ; ClassDescriptor refCld = getClassDescriptor ( refClass ) ; refPkValues = brokerHelper . getKeyValues ( refCld , referencedObject , false ) ; } for ( int i = 0 ; i < objFkFields . length ; i ++ ) { fld = objFkFields [ i ] ; if ( refPkValues != null || ! fld . isPrimaryKey ( ) ) { fld . getPersistentField ( ) . set ( targetObject , refPkValues != null ? refPkValues [ i ] . getValue ( ) : null ) ; } } }
Set the FK value on the target object, extracted from the referenced object. If the referenced object was
<i>null</i> the FK values were set to <i>null</i>, expect when the FK field was declared as PK.

@param targetObject real (non-proxy) target object
@param cld {@link ClassDescriptor} of the real target object
@param rds An {@link ObjectReferenceDescriptor} or {@link CollectionDescriptor}
@param referencedObject The referenced object or <i>null</i>