I upgraded from Spring Boot (Data) 3.1.5 to 3.2.0.
Several of my queries in the Repositories throw exceptions now on application start in the validation phase:
Caused by: Cannot compare left expression of type 'java.lang.Object' with right expression of type 'java.lang.Long'.
E.g.:
@Query(value = "SELECT new com.my.service.crud.ReferencedObject(p.id, p.name, r.name) FROM MyEntityA p join MyEntityB r on (p.aId = r.id) WHERE " +
" p.aId = :projectId and exists (select id from EntityC where cId = p.id and dTypeId = :uutId)")
List<ReferencedObject> findReferencesToUtilType(@Param("projectId") Long projectId, @Param("uutId") Long utilTypeId);
This (anonymized) Code worked fine with 3.1.5 and returned a list of ReferencedObjects.
I even get errors on finders that return Optional<Entity>
and e.g. findByIdAndOtherAttr(...)
.
The underlying cause is
Caused by: org.hibernate.query.SemanticException: Cannot compare left expression of type 'java.lang.Long' with right expression of type 'java.lang.Object'
at org.hibernate.query.sqm.internal.TypecheckUtil.assertComparable(TypecheckUtil.java:338)
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.hql.internal.SemanticQueryBuilder.createComparisonPredicate(SemanticQueryBuilder.java:2447)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitComparisonPredicate(SemanticQueryBuilder.java:2391)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitComparisonPredicate(SemanticQueryBuilder.java:268)
at org.hibernate.grammars.hql.HqlParser$ComparisonPredicateContext.accept(HqlParser.java:6071)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitGroupedPredicate(SemanticQueryBuilder.java:2251)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitGroupedPredicate(SemanticQueryBuilder.java:268)
at org.hibernate.grammars.hql.HqlParser$GroupedPredicateContext.accept(HqlParser.java:5994)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.consumeJoin(SemanticQueryBuilder.java:2129)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitEntityWithJoins(SemanticQueryBuilder.java:1921)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitFromClause(SemanticQueryBuilder.java:1900)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitQuery(SemanticQueryBuilder.java:1147)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitQuerySpecExpression(SemanticQueryBuilder.java:940)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitQuerySpecExpression(SemanticQueryBuilder.java:268)
at org.hibernate.grammars.hql.HqlParser$QuerySpecExpressionContext.accept(HqlParser.java:1844)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitSimpleQueryGroup(SemanticQueryBuilder.java:925)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitSimpleQueryGroup(SemanticQueryBuilder.java:268)
at org.hibernate.grammars.hql.HqlParser$SimpleQueryGroupContext.accept(HqlParser.java:1718)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitSelectStatement(SemanticQueryBuilder.java:442)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitStatement(SemanticQueryBuilder.java:401)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.buildSemanticModel(SemanticQueryBuilder.java:310)
at org.hibernate.query.hql.internal.StandardHqlTranslator.translate(StandardHqlTranslator.java:71)
at org.hibernate.query.internal.QueryInterpretationCacheStandardImpl.createHqlInterpretation(QueryInterpretationCacheStandardImpl.java:165)
at org.hibernate.query.internal.QueryInterpretationCacheStandardImpl.resolveHqlInterpretation(QueryInterpretationCacheStandardImpl.java:147)
at org.hibernate.internal.AbstractSharedSessionContract.interpretHql(AbstractSharedSessionContract.java:744)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:794)
... 43 common frames omitted
I found this 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/5 where the Hibernate Team member said, that one is comparing apples with oranges...
Does anyone have a link to a migration guide?
What do I have to do to get my queries working again?
In the release notes of Spring Boot 3.2.0 I only found a hint that "deprecated features have been dereleased now".
Thanks for any hint!