spring-data-jpa
spring-data-jpa copied to clipboard
Spring Data JPA Query with Class Constructor: org.hibernate.query.SemanticException: Cannot compare ...
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:
- CAST(SUBDATE... AS localdate) -> CAST(SUBDATE... AS date) ...this works, but the time will be removed
- CAST(SUBDATE... AS localdatetime) -> CAST(SUBDATE... AS timestamp(6)) ...this does not work because MariaDB doesn't support data type timestamp
- CAST(SUBDATE... AS instant) ->CAST(SUBDATE... AS timestamp(6) with time zone) ... what is this???
Am I missing something for my update or could this be a bug?
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.
Domain class field data type, MariaDB version and DB table field data type. Do you need some more information?
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.
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.