次のようなモデル オブジェクトの関係があります。
@Table(name="cables")
class Cable {
@Id
private Long id;
@Column(name="dstport_id")
private Port dstPort;
@Column(name="srcport_id")
private Port srcPort;
}
@Table(name="ports")
class Port {
@Id
private Long id;
private Cable cable; // Here's the mapping that should point to cables.dstport_id or cables.srcport_id whatever is present
}
この関係では、マッピングは Cable の dstport_id または srcport_id 列による 1 対 1 のマッピングです。ケーブルは、1 つまたは 2 つの (完全に異なる) ポートに接続できません。ポートは、ケーブルに接続しないか、または 1 本のケーブルのみに接続し、いずれかのエンドポイントに接続できます。では、Hibernate でそのような関係を Port エンティティ内にマップする方法はありますか (Cable エンティティ内にマップするためのトリックはありません)。