OneToOne oneToOneAnn = relationField.getAnnotation(OneToOne.class);
boolean isJoinedByPK = relationField.isAnnotationPresent(PrimaryKeyJoinColumn.class);
boolean isJoinedByFK = relationField.isAnnotationPresent(JoinColumn.class);
Relation relation = new Relation(relationField, targetEntity, null, oneToOneAnn.fetch(),
Arrays.asList(oneToOneAnn.cascade()), oneToOneAnn.optional(), oneToOneAnn.mappedBy(),
Relation.ForeignKey.ONE_TO_ONE);
if (relationField.isAnnotationPresent(AssociationOverride.class))
{
AssociationOverride annotation = relationField.getAnnotation(AssociationOverride.class);
JoinColumn[] joinColumns = annotation.joinColumns();
relation.setJoinColumnName(joinColumns[0].name());
JoinTable joinTable = annotation.joinTable();
onJoinTable(joinTable);
}
else if (isJoinedByPK)
{
relation.setJoinedByPrimaryKey(true);
EntityMetadata joinClassMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata,
targetEntity.getClass());
relation.setJoinColumnName(joinClassMetadata != null ? ((AbstractAttribute) joinClassMetadata
.getIdAttribute()).getJPAColumnName() : null);
}
else if (isJoinedByFK)
{
JoinColumn joinColumnAnn = relationField.getAnnotation(JoinColumn.class);
relation.setJoinColumnName(joinColumnAnn.name());
}
relation.setBiDirectionalField(metadata.getEntityClazz());
metadata.addRelation(relationField.getName(), relation);
}