* @param relation
*/
public void setProxyRelationObject(Object entity, Map<String, Object> relationsMap, EntityMetadata m,
PersistenceDelegator pd, Object entityId, Relation relation)
{
KunderaMetadata kunderaMetadata = pd.getKunderaMetadata();
String relationName = MetadataUtils.getMappedName(m, relation, kunderaMetadata);
Object relationValue = relationsMap != null ? relationsMap.get(relationName) : null;
if ((relation.getType().equals(ForeignKey.ONE_TO_ONE) || relation.getType().equals(ForeignKey.MANY_TO_ONE)))
{ // One-To-One or Many-To-One relationship
Field biDirectionalField = relation.getBiDirectionalField();
boolean isBidirectionalRelation = (biDirectionalField != null);
if (isBidirectionalRelation && (relationValue == null && !relation.isJoinedByPrimaryKey()))
{
EntityMetadata parentEntityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata,
relation.getTargetEntity());
Object owner = null;
String entityName = m.getEntityClazz().getName() + "_" + entityId + "#"
+ relation.getProperty().getName();
KunderaProxy kp = kunderaMetadata.getCoreMetadata().getLazyInitializerFactory().getProxy(entityName);
if (kp != null)
{
owner = kp.getKunderaLazyInitializer().getOwner();
if (owner != null && owner.getClass().equals(parentEntityMetadata.getEntityClazz()))