Alexander B (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5be2b57...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNDBlOTdmYjQ4...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16674?atlOrigin=eyJpIjoiNDBlOT...
) HHH-16674 (
https://hibernate.atlassian.net/browse/HHH-16674?atlOrigin=eyJpIjoiNDBlOT...
) Query Path comparison not working for primary keys (
https://hibernate.atlassian.net/browse/HHH-16674?atlOrigin=eyJpIjoiNDBlOT...
)
Issue Type: Bug Assignee: Unassigned Components: hibernate-core Created: 23/May/2023 02:31
AM Environment: Spring Boot 3.1.0
Hibernate Core 6.2.2.Final
Java 17 Temurin
OS independent
MySQL/MariaDB Priority: Major Reporter: Alexander B (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5be2b57...
)
Before Version 6.2 it was possible to just write the primary key (mostly a long ) of the
type referenced in CriteriaBuilder's equal , in , ...-Methods.
Since Version 6.2 this no longer works. This is mentioned in the
https://docs.jboss.org/hibernate/orm/6.2/migration-guide/migration-guide....
however I assume that the Primary Keys have been overlooked.
e.g. the following Code fails
...
final CriteriaBuilder cb = this.getEntityManager().getCriteriaBuilder();
final CriteriaQuery<UserAuthLog> cq = cb.createQuery(UserAuthLog.class);
final Root<UserAuthLog> root = cq.from(UserAuthLog.class);
cq.select(root);
// Problem here
cq.where(cb.equal(root.get(UserAuthLog_.user), userId));
...
where the class UserAuthLog looks like this:
...
@NotNull
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(
name = "user_id",
foreignKey = @jakarta.persistence.ForeignKey(value = ConstraintMode.CONSTRAINT)
)
private UserDetail user;
...
and UserDetail like this
public class UserDetail
{
...
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
private long id;
...
with the following exception
Caused by: java.lang.IllegalArgumentException: Can't compare test expression of type
[UserDetail] with element of type [basicType(a)1228(java.lang.Long,-5)]
at
org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder.assertComparable(SqmCriteriaNodeBuilder.java:2098)
at
org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder.equal(SqmCriteriaNodeBuilder.java:2121)
at
org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder.equal(SqmCriteriaNodeBuilder.java:182)
at XXX.getUserLoginLogs(XXX.java:39)
...
Also consider that some methods like in use collections with primary keys.
The changes were done here:
https://github.com/hibernate/hibernate-orm/pull/6189 /
https://hibernate.atlassian.net/browse/HHH-15802
If this can’t be fixed it would be great if could somehow disable this early query path
comparison, so that we don’t have to check our entire DAL-Layer (we are talking about
thousands of lines of code) for problems.
(
https://hibernate.atlassian.net/browse/HHH-16674#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16674#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:bbd69a1 )