简体   繁体   English

根据特定条件获取ManytoOne

[英]Fetch ManytoOne based on certain condition

I am using Hibernate 3.5.4 version as Orm I have two tables which have many to one relationship , Like Table 'Book' can have many 'Authors' associated with It. 我正在使用Hibernate 3.5.4版本作为Orm,我有两个具有多对一关系的表,就像表'Book'可以有许多与其关联的'Authors'。

@OneToMany(mappedBy = "key.bookId", fetch = FetchType.EAGER, cascade = CascadeType.ALL)   
public Set<BookAuthor> getAuthors() {
    return authors;
}

But we use soft delete for deleting the association (we maintain a column named isDeleted ) , i want to fetch the entity based on isDeleted check if its 1 it should not be loaded , else if 0 load it. 但是我们使用软删除来删除关联(我们维护名为isDeleted的列),我想基于isDeleted获取实体,检查是否应加载它的1,否则应加载0。

Is it possible by modifying this current fetching strategy to provide above support or there is another better solution that can be applied please let me know. 是否可以通过修改当前的获取策略来提供上述支持,或者可以应用其他更好的解决方案,请告诉我。

Have a look at the @Filter or @Where Annotation. 看一下@Filter@Where注释。

As far as I know this is the usual way to restrict collection fetching. 据我所知,这是限制集合获取的常用方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM