Just upgraded from Spring Boot 3.1.5 to 3.2.0 and started having Cannot compare left expression of type 'com.acme.domain.AbstractEntity' with right expression of type 'com.acme.domain.User'
in several of our repositories.
The definitions are:
public class Auditing<T extends AbstractEntity & Identifiable, E extends Enum<?>>
...
public class User extends AbstractEntity implements Identifiable<Long>
...
public class AuditEventUser extends Auditing<User, UserEventType>
...
Where Identifiable<T>
is an interface just with a T getId()
method.
And the failing query:
@Query("""
SELECT MAX(h.eventInstant)
FROM User u
JOIN AuditEventUser a ON a.entity = u
JOIN a.eventHistory h
WHERE u.username = :username
AND a.event = :event
""")
Instant getUserEventInstant(@Param("username") String username, @Param("event") UserEventType event);
I have thoroughly checked other similar questions and they mostly suggest upgrading to Hibernate 6.4, but it seems an unrelated problem. In our case it seems that Hibernate is flat out ignoring the Identifiable bound and fails to find an id on AbstractEntity. What do we have to do to get our queries working again?
ALso found this Validation failed for query for method upgrading from Spring Boot 3.1.5 to 3.2.0 but the accepted answer is just a workaround that we cannot afford.