spring-projects / spring-data-jpa

Simplifies the development of creating a JPA-based data access layer.
https://spring.io/projects/spring-data-jpa/
Apache License 2.0
2.93k stars 1.39k forks source link

Spring Data JPA Query with Class Constructor: org.hibernate.query.SemanticException: Cannot compare ... #3424

Closed fucch closed 2 months ago

fucch commented 2 months ago

I updated org.springframework.boot in my Gradle 8.7 project from version 3.1.8 to version 3.2.4. The project uses MariaDB. Now I get following error for my Spring Data JPA Query: org.hibernate.query.SemanticException: Cannot compare left expression of type 'java.time.Instant' with right expression of type 'java.lang.Object'

Here is my Query... ap.dateCreated has data type Instant in the Domain class and data type datetime in MariaDB: @Query(value = "SELECT new de.dvinci.reportingservice.repository.pojo.ApplicationPaperDateRangeCounts(" + "SUM(CASE WHEN ap.dateCreated >= SUBDATE(NOW(), :interval) THEN 1 ELSE 0 END), " + "SUM(CASE WHEN ap.dateCreated >= SUBDATE(NOW(), :interval * 2) AND ap.dateCreated < SUBDATE(NOW(), :interval) THEN 1 ELSE 0 END)) " + "FROM ApplicationPaper ap " + "WHERE ap.jobOpening = :jobOpening AND ap.dateCreated >= SUBDATE(NOW(), :interval * 2)") ApplicationPaperDateRangeCounts getCountsByDateRange( @Param("jobOpening") JobOpening jobOpening, @Param("interval") Integer interval);

I have tried converting the return value of SUBDATE in the Query -> MariaDB executed query:

Am I missing something for my update or could this be a bug?

mp911de commented 2 months ago

Care to attach more details such as your entity model? Ideally you can provide a minimal yet complete sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

fucch commented 2 months ago

Entity model

Domain class field data type, MariaDB version and DB table field data type. Do you need some more information?

spring-projects-issues commented 2 months ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues commented 2 months ago

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.