Spring Boot 3.2.0升级到3.2.1后查询执行错误

问题描述 投票:0回答:1

我有一个带有大量查询的 Java Spring 应用程序,到目前为止一直有效,直到 spring boot 3.2.0

最近,简单地更改为 spring boot 3.2.1 后,我开始收到这种错误:

org.hibernate.query.sqm.produce.function.FunctionArgumentException: Function argument [org.hibernate.query.sqm.tree.expression.SqmLiteralNull@5bd97ebe] of type [org.hibernate.query.sqm.tree.expression.NullSqmExpressible@3f8a721f] at specified position [2] in call arguments was not typed as an allowable function return type

我的 pom 依赖项如下所示:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.1</version>
        <relativePath />
    </parent>

    <properties>
        <java.version>21</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        
        <dependency>
            <groupId>com.oracle.database.jdbc</groupId>
            <artifactId>ojdbc11</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>

    </dependencies>

我的查询,删除了一些我无法透露的代码,但仍然给出错误,条件很简单:

    
    @Query("select org  "
         + "  from Organization         org     "
         + " where 1 = 1 "
         + "   and ( "
         + "         coalesce(:#{#request.name},null) is null "
         + "         or "
         + "         trim(:#{#request.name}) = '' "
         + "         or "
         + "         lower(org.name) like lower(trim(:#{#request.name}))"
         + "       ) "
    )
    Page<Organization> getPageByCriteria(@Param("request") GetOrganizationsRequestDto request, Pageable pageable);

我正在连接到 oracle 数据库版本 11g

有人有此类问题或类似问题可以帮助我吗?

谢谢

java spring hql
1个回答
0
投票

合并预期的非空参数,因此您应该删除

null
参数。

从你原来的方法转换过来,应该和这个一样:

select org from Organization org
where 1 = 1
and (:#{#request.name} is null
   or trim(:#{#request.name}) = ''
   or lower(org.name) like lower(trim(:#{#request.name}))
)
© www.soinside.com 2019 - 2024. All rights reserved.