private Object getValue(CoreAbstractSession session, Reference reference, CacheId primaryKey, ErrorHandler handler) {
Class referenceTargetClass = reference.getTargetClass();
if(null == referenceTargetClass || referenceTargetClass == CoreClassConstants.OBJECT) {
for(Object entry : session.getDescriptors().values()) {
Object value = null;
Descriptor targetDescriptor = (Descriptor) entry;
List pkFields = targetDescriptor.getPrimaryKeyFields();
if(null != pkFields && 1 == pkFields.size()) {
Field pkField = (Field) pkFields.get(0);
pkField = (Field) targetDescriptor.getTypedField(pkField);
Class targetType = pkField.getType();
if(targetType == CoreClassConstants.STRING || targetType == CoreClassConstants.OBJECT) {
value = getValue(targetDescriptor.getJavaClass(), primaryKey);
} else {
try {
Object[] pkValues = primaryKey.getPrimaryKey();
Object[] convertedPkValues = new Object[pkValues.length];
for(int x=0; x<pkValues.length; x++) {
convertedPkValues[x] = session.getDatasourcePlatform().getConversionManager().convertObject(pkValues[x], targetType);
}
value = getValue(targetDescriptor.getJavaClass(), new CacheId(convertedPkValues));
} catch(ConversionException e) {
}
}
if(null != value) {
return value;
}
}
}
if(primaryKey.getPrimaryKey()[0] != null){
XMLMarshalException e = XMLMarshalException.missingIDForIDRef(Object.class.getName(), primaryKey.getPrimaryKey());
if(handler != null){
SAXParseException saxParseException = new SAXParseException(e.getLocalizedMessage(), null, e);
try{
handler.warning(saxParseException);
}catch(SAXException saxException){
throw e;
}
}
}
return null;
} else {
Object value = getValue(referenceTargetClass, primaryKey);
if(null == value) {
CoreMapping mapping = (CoreMapping) reference.getMapping();
CoreDescriptor targetDescriptor = mapping.getReferenceDescriptor();
if(targetDescriptor.hasInheritance()) {
CoreInheritancePolicy inheritancePolicy = targetDescriptor.getInheritancePolicy();
List<CoreDescriptor> childDescriptors = inheritancePolicy.getAllChildDescriptors();
for(CoreDescriptor childDescriptor : childDescriptors) {
value = getValue(childDescriptor.getJavaClass(), primaryKey);
if(null != value) {
return value;