JpaJoinColumn jpaJoin = (JpaJoinColumn) path.getObject();
JpaRelationship jpaRelationship = (JpaRelationship) path.getObjectParent();
JpaEntity targetEntity = context.getEntityMap().entityForClass(
jpaRelationship.getTargetEntityName());
JpaId jpaTargetId = targetEntity.getAttributes().getId(
jpaJoin.getReferencedColumnName());
ObjRelationship objRelationship = (ObjRelationship) targetPath.getObject();
DataMap dataMap = objRelationship.getSourceEntity().getDataMap();
// add FK
DbAttribute src = new DbAttribute(jpaJoin.getName());
// TODO: andrus, 5/2/2006 - infer this from Jpa relationship
src.setMandatory(false);
src.setMaxLength(jpaTargetId.getColumn().getLength());
src.setType(jpaTargetId.getDefaultJdbcType());
DbEntity srcEntity = dataMap.getDbEntity(jpaJoin.getTable());
srcEntity.addAttribute(src);
// add join
DbRelationship dbRelationship = (DbRelationship) objRelationship
.getDbRelationships()
.get(0);
DbRelationship reverseRelationship = dbRelationship.getReverseRelationship();
if (reverseRelationship == null) {
reverseRelationship = dbRelationship.createReverseRelationship();
}
DbJoin join = new DbJoin(dbRelationship, src.getName(), jpaTargetId
.getColumn()
.getName());
DbJoin reverseJoin = join.createReverseJoin();
reverseJoin.setRelationship(reverseRelationship);