Alexander B (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5be2b57...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZGY0MWM0NDVl...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16674?atlOrigin=eyJpIjoiZGY0MW...
) HHH-16674 (
https://hibernate.atlassian.net/browse/HHH-16674?atlOrigin=eyJpIjoiZGY0MW...
) Query Path comparison not working for primary keys (
https://hibernate.atlassian.net/browse/HHH-16674?atlOrigin=eyJpIjoiZGY0MW...
)
Change By: 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
{code:java}...
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));
...{code}
where the class {{UserAuthLog}} looks like this:
{noformat} ...
@NotNull
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(
name = "user_id",
foreignKey = @jakarta.persistence.ForeignKey(value = ConstraintMode.CONSTRAINT)
)
private UserDetail user;
...{noformat}
and {{UserDetail}} like this
{code:java}public class UserDetail
{
...
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
private long id;
...{code}
with the following exception
{code:java}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)
...{code}
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://github.com/h...
[
https://hibernate.atlassian.net/browse/HHH-15802|https://hibernate.atlass...]
If this can’t be fixed it would be great if we 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 )