可以在查询 DSL 中为 Parent 分配 Child 吗?
Can assign Child for Parent in Query DSL?
有 QParent、QChild1 和 QChild2
我尝试使用 QParent 而不是每个 child.
包含所有谓词的class
class Filter {
private QParent query;
public Filter(QParent query) {
this.query = query;
}
BooleanExpression getPredicates(String name) {
name == null ? null : query.name.eq(name);
return query.isNotNull().and(name);
}
}
然后我发送一个 child 作为 Filter 构造函数的参数
childOneRepo.findAll(new Filter(QChild1.child1).getPredicates("test name"));
但是new Filter(QChild1.child1)
给我一个错误。
尽管 child1 和 child2 扩展了 parent class。
虽然实体相互扩展,但查询类型却没有。相反,您必须使用 new Filter(QChild1.child1._super)
.
有 QParent、QChild1 和 QChild2 我尝试使用 QParent 而不是每个 child.
包含所有谓词的class
class Filter {
private QParent query;
public Filter(QParent query) {
this.query = query;
}
BooleanExpression getPredicates(String name) {
name == null ? null : query.name.eq(name);
return query.isNotNull().and(name);
}
}
然后我发送一个 child 作为 Filter 构造函数的参数
childOneRepo.findAll(new Filter(QChild1.child1).getPredicates("test name"));
但是new Filter(QChild1.child1)
给我一个错误。
尽管 child1 和 child2 扩展了 parent class。
虽然实体相互扩展,但查询类型却没有。相反,您必须使用 new Filter(QChild1.child1._super)
.