【发布时间】:2018-10-25 12:29:22
【问题描述】:
所以我有一个 NamedQuery,其中字段通过来自 Repo 的 enityManager.createNamedQuery 传递。
所以我有两个字段,areaId 和 fieldId,areaId 会一直存在,但 fieldId 有时会为空。
如果 :fieldId 为空,我如何省略(删除)以下行
and summary.bucket.fieldId.id = :fieldId --line to be removed
以下是我尝试使用案例场景的尝试,但这不起作用。
我愿意接受最好的方法或指导吗?
@NamedQuery(name = "SummaryBySubstatus.getInfo",
query = "select new com.model.group.summaryGroup(summary.bucket.area.id,"
summary.bucket.facilityProductInfo,
from SummaryBySubstatus as summary
where summary.bucket.area.id = :areaId
and summary.bucket.fieldId.id = :fieldId
---Tried This way---
and(case when :fieldId != null then summary.bucket.fieldId.id = :fieldId end)"
【问题讨论】:
标签: spring hibernate jpa entitymanager named-query