Search code examples
javaoracle-databasespring-bootmigrationhql

Query execution errors after upgrading spring boot 3.2.0 to 3.2.1 - ORA-00933 - command not properly ended


I have a Java Spring application with lots of queries, which so far have worked until spring boot 3.2.0.

Recently, after simply changing to spring boot 3.2.1, I started getting this kind of error:

org.springframework.dao.InvalidDataAccessResourceUsageException: JDBC exception executing 
SQL [select 
        o1_0.org_id,
        o1_0.name 
     from organizations o1_0 
     where (
            ? is null or 
            trim(BOTH from ?)='' or 
            lower(o1_0.name) like lower(trim(BOTH from ?))
     ) 
     offset ? rows 
     fetch first ? rows only] 
[ORA-00933: comando SQL command not properly ended]

My pom dependencies look like this:

    <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>

My queries, with some code i cant disclose removed, but still giving errors, has simple conditions:

    
    @Query("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}))"
         + "       ) "
    )
    Page<Organization> getPageByCriteria(@Param("request") GetOrganizationsRequestDto request, Pageable pageable);

I am connecting to oracle database version 11g

Does anyone have this kind of problem or similar and can help me with it? I suspect it is related to ojdbc not having had an update since the last spring boot version.

Thanks

Edit: added the pure SQL query performed on the database, according to error log


Solution

  • Starting from 6.2 Hibernate team have started dropping support of unsupported DBs (please read Hibernate ORM 6.2 - DB version support, Remove support for Oracle versions older than 19, Remove support for Oracle versions older than 11.2), however, some of those DBs are still (partially) supported via hibernate-community-dialects module. You need to add hibernate-community-dialects dependency to your project:

    <dependency>
      <groupId>org.hibernate.orm</groupId>
      <artifactId>hibernate-community-dialects</artifactId>
    </dependency>
    

    and, most probably, set spring.jpa.properties.hibernate.dialect to Oracle10g in application.properties