Hibernate @Filter on @ManyToOne

十年热恋 提交于 2019-12-05 13:40:21

You can try this: instead of the @Filter on the @ManyToOne field, add this filter on class Foo:

@Filter(name = "foo_active", condition = "bar in (select id from Bar where state = 'active')")

Note though that this may result in an inefficient query.

I faced the same issue with @Filter when using along with @ManyToOne recently. The trick is to use @Filter on the target entity not on the association.

@Entity
@Table(name = "foo")
@Filter(name = "foo_active", condition = "state='active'")
public class Bar

and the association in Foo class should be like:

@ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
@JoinColumn(name = "bar")
private Bar bar;

Hope this helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!