spring-data-jpa icon indicating copy to clipboard operation
spring-data-jpa copied to clipboard

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

Open fucch opened this issue 1 year ago • 3 comments
trafficstars

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?

fucch avatar Apr 12 '24 15:04 fucch

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.

mp911de avatar Apr 15 '24 07:04 mp911de

Entity model

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

fucch avatar Apr 15 '24 08:04 fucch

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 avatar Apr 22 '24 13:04 spring-projects-issues

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.

spring-projects-issues avatar Apr 29 '24 13:04 spring-projects-issues