【发布时间】:2016-11-01 22:48:29
【问题描述】:
有两个表A和B:
A(id, b_id, a_other)
B(id, b_other)
A和B对应的类是这样的:
@Entity
@Table(name = "A")
public class A {
@Id
@Column(name = "id")
private Integer id;
@JoinColumn(name = "b_id", nullable = true)
@OneToOne(fetch = FetchType.EAGER)
@WhereJoinTable(clause = "b_id > 0")
private B b;
@Column(name = "a_other")
private Integer aOther;
}
public class B {
@Id
@Column(name = "id")
private Integer id;
@Column(name = "b_other")
private Integer bOther;
}
我想要的查询是这样的:
select * from A left join B on A.b_id = B.id and A.b_id != 0;
您可能会发现的痛点是额外的连接条件 A.b_id != 0
我在A类中附加@WhereJoinTable(clause = "b_id > 0"),但它没有任何意义,因为我发现它根本不起作用。
我将@WhereJoinTable 更改为@Where,我发现没有任何变化,谁能帮忙找出缺少的东西?
提前致谢。
【问题讨论】: