我有两个休眠映射实体A和B.
A有2个实体B的集合,我想根据B中保存的属性过滤每个集合(如下面的代码所示).
@FilterDefs()
class A{
@OneToMany(mappedBy = "productType", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@Filter(name = "something", condition = "entityType = 'SKU1'")
Set set1 = new HashSet();
@OneToMany(mappedBy = "productType", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@Filter(name = "something", condition = "entityType = 'SKU2'")
Set set2 = new HashSet();
}
class B{
@ManyToOne(cascade = CascadeType.ALL)
private A productType;
@Column(name = "entity_type")
@Enumerated(EnumType.STRING)
private EntityType entityType;
}
编辑:
我在DAO方法中按照以下建议启用过滤器.但是,我收到以下异常
org.hibernate.exception.SQLGrammarException: could not initialize a
collection
如果我使用急切的加载方法,我得到一个例外,无法生成无效的SQL?
有什么指针吗?