public void retrieveReference ( Object pInstance , String pAttributeName ) throws PersistenceBrokerException { if ( logger . isDebugEnabled ( ) ) { logger . debug ( "Retrieving reference named [" + pAttributeName + "] on object of type [" + pInstance . getClass ( ) . getName ( ) + "]" ) ; } ClassDescriptor cld = getClassDescriptor ( pInstance . getClass ( ) ) ; CollectionDescriptor cod = cld . getCollectionDescriptorByName ( pAttributeName ) ; getInternalCache ( ) . enableMaterializationCache ( ) ; // to avoid problems with circular references, locally cache the current object instance Identity oid = serviceIdentity ( ) . buildIdentity ( pInstance ) ; boolean needLocalRemove = false ; if ( getInternalCache ( ) . doLocalLookup ( oid ) == null ) { getInternalCache ( ) . doInternalCache ( oid , pInstance , MaterializationCache . TYPE_TEMP ) ; needLocalRemove = true ; } try { if ( cod != null ) { referencesBroker . retrieveCollection ( pInstance , cld , cod , true ) ; } else { ObjectReferenceDescriptor ord = cld . getObjectReferenceDescriptorByName ( pAttributeName ) ; if ( ord != null ) { referencesBroker . retrieveReference ( pInstance , cld , ord , true ) ; } else { throw new PersistenceBrokerException ( "did not find attribute " + pAttributeName + " for class " + pInstance . getClass ( ) . getName ( ) ) ; } } // do locally remove the object to avoid problems with object state detection (insert/update), // because objects found in the cache detected as 'old' means 'update' if ( needLocalRemove ) getInternalCache ( ) . doLocalRemove ( oid ) ; getInternalCache ( ) . disableMaterializationCache ( ) ; } catch ( RuntimeException e ) { getInternalCache ( ) . doLocalClear ( ) ; throw e ; } }
retrieve a single reference - or collection attribute of a persistent instance .