【发布时间】:2014-05-07 05:33:28
【问题描述】:
我们正在对实体进行搜索,我们正在使用 Query DSL。
表结构如下
TableA : shop -> has manytoOne relationship to TableB : Discount
我们需要建立一个谓词来返回所有没有打折的商店
Sale 也就是打折的 Sale 。
我们使用 MySQL 数据库和 JPA 作为我们的持久性框架。
场景是我们正在执行搜索,搜索应该找到所有没有折扣的商店和批准折扣的商店。
以下是我们目前拥有的布尔表达式。
BooleanExpression A = shop.id.eq(SomeId);
BooleanExpression B = shop.name.eq(SomeName)
BooleanExpression C = shop.discount.isNotNull;
BooleanExpression D = shop.discount.isNull;
BooleanExpression E = shop.disccount.approved.eq(SomeValue)
现在我们需要构建查询来获取所有没有折扣的商店,以及所有有折扣和批准的商店。
我们尝试了谓词
A
.and(B)
.and(D .or(C.and(D).and(E))
)
我们希望查询是
where shop.id=#someid and shop.name = 'some name' and (shop.discount is Null Or (shop.discount is not null and shop.approved='#some Value'))
但是生成的查询是
where shop.id=`#someid` and shop.name = `'some name'` and (shop.discount is Null Or shop.discount is not null and shop.approved='`#some Value`')
我们没有用这个谓词得到正确的结果集,
有什么方法可以重写谓词以使其按预期工作?请帮助我提出建议。
谢谢 萨拉瓦娜。
【问题讨论】:
标签: querydsl