//find the appropriate reference key, can be in a join
Iterator joinsIt = referencedEntity.getJoinIterator();
KeyValue key = null;
while ( joinsIt.hasNext() ) {
Join join = (Join) joinsIt.next();
if ( join.containsProperty( property ) ) {
key = join.getKey();
break;
}
}
if ( key == null ) key = property.getPersistentClass().getIdentifier();