java对Spring数据的条件查询JPA在DB2(z/OS)上给出了一个417错误
我目前在Spring Data Crudepository中有以下方法签名:
@Query("SELECT c FROM Table c WHERE (:paramOne is null or c.fieldOne = :paramOne) AND (:paramTwo is null or c.fieldTwo = :paramTwo)")
Iterable<Table> findByParamOneAndParamTwo(@Param("paramOne") Integer p1, @Param("paramTwo") Integer p2);
Hibernate将其转换为(简化):
select * where (? is null or fieldOne=?) and (? is null or fieldTwo=?)
我使用这个方法来获得一个既可以过滤表又可以返回所有记录的方法
我的问题是,当我尝试并执行存储库的方法时,会得到一个负的417(-417)Db2错误。谷歌上说这意味着
A statement string to be prepared includes parameter markers as the operands of the same operator (for example: ? > ?)
即使我的Hibernate查询没有这样做
# 1 楼答案
也许您需要将检查PARM是否为null的逻辑推送到应用程序,因为null谓词中不支持参数标记:“不能为表达式或在表达式中指定参数标记。”(https://www.ibm.com/support/knowledgecenter/SSEPEK_11.0.0/sqlref/src/tpc/db2z_nullpredicate.html)。SQLCODE-417的消息文本可以改进