Hibernate为表/列引用两次创建的交叉联接

时间:2019-06-17 21:20:19

标签: hibernate

假设我们在Hibernate域对象中引用了2个单独的相同类型的子对象。

//uni-directional one-to-one association to Person
@OneToOne
@JoinColumn(name="ACKNOWLEDGE_BY", referencedColumnName="UNIQUEIDENTIFIER")
private Person acknowledgeBy;

//uni-directional one-to-one association to Person
@OneToOne
@JoinColumn(name="UNIQUEIDENTIFIER", referencedColumnName="UNIQUEIDENTIFIER")
private Person employee;

此结构始终会向CROSS JOIN表生成Person,这是不正确的。我们的目标是摆脱CROSS JOIN,并将其作为单独的外部联接。

为什么会产生CROSS JOIN

1 个答案:

答案 0 :(得分:0)

很难理解你想要什么...

您能尝试这个答案吗?

@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "ACKNOWLEDGE_BY", unique = true)
private Person acknowledgeBy;

@OneToOne
@JoinColumn(name="UNIQUEIDENTIFIER", unique = true)
private Person employee;
//...