spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.91k stars 40.63k forks source link

org.hibernate.query.SemanticException: Cannot compare left expression of type 'com.example.demo.CompositeEntity$Another' with right expression of type 'java.lang.Long' #40853

Closed Amruta9191 closed 4 months ago

Amruta9191 commented 4 months ago

have updated my spring boot project, following are the updated dependencies

  1. Java 11 - Java 21
  2. Springboot 2.7.8 to 3.2.3
  3. Servlet 6.0
  4. JPA 3.1
  5. Hibernate 6
  6. Spring security 6

I am facing below issue:

org.hibernate.query.SemanticException: Cannot compare left expression of type 'com.example.demo.CompositeEntity$Another' with right expression of type 'java.lang.Long'
    at org.hibernate.query.sqm.internal.TypecheckUtil.assertComparable(TypecheckUtil.java:358)
    at org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate.<init>(SqmComparisonPredicate.java:48)
    at org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate.<init>(SqmComparisonPredicate.java:34)
    at org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder.equal(SqmCriteriaNodeBuilder.java:2132)
    at org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder.equal(SqmCriteriaNodeBuilder.java:192)
    at com.example.demo.LocalDataRepository.grouped(LocalDataRepository.java:29)
    at com.example.demo.LocalDataRepositoryIntegrationTest.testShouldFindAnotherById(LocalDataRepositoryIntegrationTest.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

SemanticIssue.zip

In prior version with Spring Boot 3.2.3 it was working fine.

I have created one demo project for same issue which is in my project.

wilkinsona commented 4 months ago

Thanks for the report. I believe that this is a bug in your query building that's now being caught due to some improvements in Hibernate. You're asking it to compare a long and a CompositeEntity$Another which doesn't really make sense. Please see https://discourse.hibernate.org/t/upgrade-to-6-3-rc1-cannot-compare-left-expression-of-type-java-sql-timestamp-with-right-expression-of-type-com-model-entity-impl-user/8034 for some other examples and discussion.