public Vector createPkVectorFromKey(Object key, AbstractSession session) {
// If the descriptor primary key is mapped through direct-to-field mappings,
// then no elaborate conversion is required.
// If key is compound, add each value to the vector.
KeyElementAccessor[] pkElementArray = this.getKeyClassFields(key.getClass());
Vector pkVector = new NonSynchronizedVector(pkElementArray.length);
for (int index = 0; index < pkElementArray.length; index++) {
DatabaseMapping mapping = pkElementArray[index].getMapping();
Object fieldValue = null;
if (mapping.isDirectToFieldMapping()) {
fieldValue = ((AbstractDirectMapping)mapping).getFieldValue(pkElementArray[index].getValue(key, session), session);
} else {
fieldValue = pkElementArray[index].getValue(key, session);
if ( (fieldValue !=null) && (pkClass != null) && (mapping.isOneToOneMapping()) ){
OneToOneMapping refmapping = (OneToOneMapping)mapping;
DatabaseField targetKey = refmapping.getSourceToTargetKeyFields().get(pkElementArray[index].getDatabaseField());
CMPPolicy refPolicy = refmapping.getReferenceDescriptor().getCMPPolicy();
if (refPolicy.isCMP3Policy()){
Class pkClass = refPolicy.getPKClass();
if ((pkClass != null) && (pkClass != fieldValue.getClass()) && (!pkClass.isAssignableFrom(fieldValue.getClass()))) {
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("invalid_pk_class", new Object[] { pkClass, fieldValue.getClass() }));
}
fieldValue = ((CMP3Policy)refPolicy).getPkValueFromKeyForField(fieldValue, targetKey, session);
}
}
}
pkVector.add(fieldValue);
}
return pkVector;
}