I have a small application that uses spring boot 2.7.4 and Spring data JPA to connect to AS400. Its been working fine. Now I am trying to upgrade it to spring boot 3 and getting this error
ERROR 10876 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.dao.InvalidDataAccessResourceUsageException: could not prepare statement; SQL [select * from (select s1_0.id c0,s1_0.message c1,row_number() over() rn from table1 s1_0) r_0_ where order by r_0_.rn]] with root cause
com.ibm.as400.access.AS400JDBCSQLSyntaxErrorException: [SQL0199] Keyword BY not expected. Valid tokens: < > = <> <= !< !> != >= ¬< ¬> ¬= IN NOT.
at com.ibm.as400.access.JDError.createSQLExceptionSubClass(JDError.java:948) ~[jt400-11.1.jar:JTOpen 11.1]
I am not sure why it is creating a second select statement(with wrong syntax) to enclose the seemingly correct select statement.
build.gradle
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.0'
id 'io.spring.dependency-management' version '1.1.0'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation group: 'net.sf.jt400', name: 'jt400', version: '11.1'
implementation 'org.springframework.boot:spring-boot-starter-web'
//implementation 'com.ibm.db2:jcc'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
properties
spring.datasource.driver-class-name=com.ibm.as400.access.AS400JDBCDriver
spring.datasource.username=**
spring.datasource.password=**
spring.datasource.url=jdbc:as400://**
spring.datasource.hikari.connection-test-query:values 1
spring.jpa.generate-ddl=false
Using jpa repository
public interface Table1Repository extends JpaRepository<Table1, Long> {
}
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
@Entity
@Table(name = "TABLE1")
public class Table1 {
@Id
private Long id;
private String message;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
this is the call that is causing this error
tablel1Repository.findAll();
It was working fine with spring boot 2.7.4 and with SB 3.0.0 it is not.
Comment From: fseznec
I have raised these issues here: https://hibernate.atlassian.net/browse/HHH-15890 https://github.com/spring-projects/spring-data-jpa/issues/2732
Comment From: yellowhat007
@fseznec Thank you for the links. Glad to know it has been looked into
Comment From: wilkinsona
Spring Boot itself is not responsible for query generation. Closing in favour of the Spring Data JPA and Hibernate issues.