说我有这两个实体:
@Entity
class A {
@OneToMany(mappedBy = "a")
private Collection<B> bCollection;
...
}
@Entity
class B {
@ManyToOne
@JoinColumn(name = "aId")
private A a;
private boolean restricted;
...
}
我的问题是:如何在A.bCollection中仅使用restricted = false
获取B实体?
答案 0 :(得分:1)
使用Hibernate过滤器:
@Filter(
name = "restrictedFilter",
condition="restricted = TRUE"
)
有关详情http://www.mkyong.com/hibernate/hibernate-data-filter-example-xml-and-annotation/
,请参阅此处编辑:我遇到的解决方案比使用过滤器简单得多。使用@Where注释:
@Where(clause="restricted = TRUE")
private Collection<B> bCollection;