我有一个Entity_A
与OneToMany
有Entity_B
关系。
Entity_B
带有一个标志,指示它是否处于活动状态。
如何选择加入实体A并仅选择激活的实体B?
答案 0 :(得分:0)
SELECT DISTINCT entA FROM Entity_A entA JOIN FETCH entA.entityBSet as entB WHERE entB.active = true
更新 -尝试@where
@Entity
public class Entity_A {
@Id
@Column(name = "ID")
private Integer id;
@OneToMany(mappedBy = "entityA")
@Where("active = true")
private Set<Entity_B> entityBSet;
}
@Entity
public class Entity_B {
@Id
@Column(name = "ID")
private Integer id;
@Id
@Column(name = "ACTIVE")
private Integer active;
@ManyToOne
private Entity_A entityA;
}