1

我有两张桌子,一张是另一张的父母。子表具有确定其有效性的开始日期和结束日期列。以下过滤器设置仅适用于加载有效子项:

@Entity
@Table(name = "child")
@FilterDef(name = "dateFilter", parameters = @ParamDef( name = "targetDate", type = "string" ))
@Filter(name = "dateFilter", condition = "(:targetDate between to_char(startDate, 'yyyyMMdd') and to_char(endDate, 'yyyyMMdd')")
public class Child {}

我想要的是加载所有父母,并且只加载以父实体定义开头的有效孩子。以下代码加载所有孩子,而不仅仅是有效的孩子:

@Entity
@Table(name = "parent")
public class Parent {
    @OneToMany(mappedBy = "parent")
    private Collection<Child> childCollection = new HashSet<Child>();
}    

如何为作用于子实体的父实体类指定过滤器?

4

1 回答 1

1
@Entity
@Table(name = "parent")
@FilterDef(name = "dateFilter", parameters = @ParamDef( name = "targetDate", type = "string" ))
public class Parent {
    @OneToMany(mappedBy = "parent")
    @Filter(name = "dateFilter", condition = "(:targetDate between to_char(startDate, 'yyyyMMdd') and to_char(endDate, 'yyyyMMdd')")
    private Collection<Child> childCollection = new HashSet<Child>();
} 

并确保启用过滤器...

于 2012-07-23T20:17:46.267 回答