【发布时间】:2017-09-25 10:18:38
【问题描述】:
我正在尝试在 jpa 查询中使用 in 子句,但它给出了 Operand should contain 1 column(s) 错误。
这是我的查询:
@Query(value = "select e from Table e where " +
"((:plantId is null and :unitId is null and :functionalLocationId is null) or" +
" (:functionalLocationId is not null and e.functionalLocation.id in (select f.id from FunctionalLocation f where f.id = :functionalLocationId)) or" +
" (:unitId is not null and :functionalLocationId is null and e.functionalLocation.unit.id in (select u.id from Unit u where u.id = :unitId)) or" +
" (:plantId is not null and :unitId is null and :functionalLocationId is null and e.functionalLocation.unit.plant.id in (select p.id from Plant p where p.id = :plantId))) and" +
"((:equipmentTagNumbers) is null or e.tagNo in (:equipmentTagNumbers)) and" +
"(:startDate is null or e.lastUpdateDate >= :startDate) and" +
"(:endDate is null or e.lastUpdateDate <= :endDate)" +
"order by e.id desc")
:equipmentTagNumbers 属性是 Lis<String>,如果我为它发送 null,则查询按预期工作,但是当我发送实际数据时,它会给出错误。
有什么建议吗?
【问题讨论】:
-
您的查询有一些子查询返回超过 1 列,而您只希望 1 列,例如,“where x = (select x,y from abr)”
-
尝试添加您在其中形成查询并设置参数的 jpa 查询调用
-
@MaciejKowalski 我试过但结果是一样的
-
@kyur 您是否使用 eclipselink 作为您的 JPA 实现?刚刚遇到同样的问题,根据我的队友的说法,这是我们的 eclipselink 版本中的一个错误(另见forum.spring.io/forum/spring-projects/data/…)