After upgrading to Hibernate 6.2 from 5.x, some of our HQLs stopped working. I believe it’s due to the new “Query Path comparison” check (6.0 Migration Guide).
Example:
Entities, types, and AttributeConverter:
@Entity
public class Order {
@Convert(converter = UserIdAttributeConverter.class)
private UserId userId; // column SQL type: long, FK to user.id
}
public class UserId {
private Long id;
}
@Entity
public class User {
private Long id; // column SQL type: long
}
@Converter
public class UserIdAttributeConverter extends AttributeConverter<UserId, Long> {
...
}
The above declarations still work for entity persistence, and prior to the upgrade, the following query had worked:
from Order o
inner join User u on u.id = o.userId
Now, we got error:
Can’t compare test expression of type [BasicSqmPathSource(id : Long)] with element of type [BasicSqmPathSource(userId : UserId)]
I do understand and agree with the type checks on the query paths. However, shouldn’t the check consider the AttributeConverter
declared on the attribute? It clearly indicated that the attribute should be treated as a Long
in the database.