我使用Springboot 3.4.0并通过JPA我写了此查询:

问题描述 投票:0回答:1
2025-03-12 17:49:07,518 [http-nio-9090-exec-4]跟踪o.h.o.jdbc.bind- binding参数(2:java_object)

2025-03-12 17:49:07,518 [HTTP-NIO-9090-EXEC-4] TRACE O.H.O.JDBC.BIND-绑定参数(3:VARCHAR)

2025-03-12 17:49:07,518 [http-nio-9090-exec-4]跟踪o.h.o.jdbc.bind-绑定参数(4:integer)
和本地查询,只是其中的语句:

where a1_0.core_user_id=? and (? is null or c1_0.iso in (?)) fetch first ? rows only

<- [d55f237c-7eab-4bcd-a688-10fdb3ed09a3]
我遇到的错误是:<- [null]
<- [null]
2025-03-1217:49:07,593 [http-nio-9090-exec-4]错误c.e.c.c.c.c.customexceptionhandhandlesolesolersolver-至少提供了3个参数(s),但只有2个参数中存在于查询中 org.springframework.dao.InvalidDataAccSapiusageException:至少提供了3个参数,但只有2个参数(s) 我做了一些测试,如果我只使用? <- [50]

我希望,如果是零,则不会因OR
而访问语句

在执行和短路路径不参与此阶段之前,Query参数是静态绑定的,因此您必须在“有效”子句中转换

cu.iso in ?2

;你可以做这个

经过空的
spring-boot hibernate
1个回答
0
投票
而不是
null

do a

coalesce(?2, <empty list>)

(看起来JPA是否具有一些功能来创建
empty list

    剥离
  1. and
    子句As
    子句
    case
     when ?2 is null then true
     else cu.iso IN (?2)
    end
    
  2. 
    
© www.soinside.com 2019 - 2025. All rights reserved.