[JIRA] (HHH-16988) AssertionError in AbstractSqmPath.copyTo when using subquery correlated to root with more than 1 level in the class hierarchy
by JB Nizet (JIRA)
JB Nizet ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMTY1NGFjMTYz... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16988?atlOrigin=eyJpIjoiMTY1NG... ) HHH-16988 ( https://hibernate.atlassian.net/browse/HHH-16988?atlOrigin=eyJpIjoiMTY1NG... ) AssertionError in AbstractSqmPath.copyTo when using subquery correlated to root with more than 1 level in the class hierarchy ( https://hibernate.atlassian.net/browse/HHH-16988?atlOrigin=eyJpIjoiMTY1NG... )
Issue Type: Bug Affects Versions: 6.2.6, 6.2.7 Assignee: Unassigned Attachments: repro.zip Components: query-criteria Created: 24/Jul/2023 23:46 PM Priority: Major Reporter: JB Nizet ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
Let’s consider a hierarchy of entities : Data ← StoredData ← ContinuousStoredData, where the root Data entity has a ManyToMany with a Tag entity.
Querying, using the criteria API, the ContinuousStoredData entity with a predicate such as the following one:
Subquery<String> subquery = criteriaQuery.subquery(String.class);
Root<D> root2 = subquery.correlate(root);
subquery.select(root2.get("id"))
.where(root2.join("tags")
.get("id")
.in("a", "b"));
return cb.exists(subquery);
leads to an AssertionError with the following stack trace:
java.lang.AssertionError
at org.hibernate.query.sqm.tree.domain.AbstractSqmPath.copyTo(AbstractSqmPath.java:63)
at org.hibernate.query.sqm.tree.domain.SqmBasicValuedSimplePath.copy(SqmBasicValuedSimplePath.java:63)
at org.hibernate.query.sqm.tree.domain.SqmBasicValuedSimplePath.copy(SqmBasicValuedSimplePath.java:25)
at org.hibernate.query.sqm.tree.domain.AbstractSqmPath.copyTo(AbstractSqmPath.java:69)
at org.hibernate.query.sqm.tree.domain.AbstractSqmFrom.copyTo(AbstractSqmFrom.java:130)
at org.hibernate.query.sqm.tree.domain.AbstractSqmQualifiedJoin.copyTo(AbstractSqmQualifiedJoin.java:39)
at org.hibernate.query.sqm.tree.domain.SqmSetJoin.copy(SqmSetJoin.java:74)
at org.hibernate.query.sqm.tree.domain.SqmSetJoin.copy(SqmSetJoin.java:32)
at org.hibernate.query.sqm.tree.domain.AbstractSqmFrom.copyTo(AbstractSqmFrom.java:134)
at org.hibernate.query.sqm.tree.from.SqmRoot.copyTo(SqmRoot.java:93)
at org.hibernate.query.sqm.tree.domain.SqmCorrelatedRoot.copy(SqmCorrelatedRoot.java:41)
at org.hibernate.query.sqm.tree.domain.SqmCorrelatedRoot.copy(SqmCorrelatedRoot.java:17)
at org.hibernate.query.sqm.tree.from.SqmFromClause.<init>(SqmFromClause.java:40)
at org.hibernate.query.sqm.tree.from.SqmFromClause.copy(SqmFromClause.java:46)
at org.hibernate.query.sqm.tree.select.SqmQuerySpec.copy(SqmQuerySpec.java:101)
at org.hibernate.query.sqm.tree.select.SqmQuerySpec.copy(SqmQuerySpec.java:56)
at org.hibernate.query.sqm.tree.select.SqmSubQuery.copy(SqmSubQuery.java:149)
at org.hibernate.query.sqm.tree.select.SqmSubQuery.copy(SqmSubQuery.java:75)
at org.hibernate.query.sqm.tree.predicate.SqmExistsPredicate.copy(SqmExistsPredicate.java:45)
at org.hibernate.query.sqm.tree.predicate.SqmExistsPredicate.copy(SqmExistsPredicate.java:17)
at org.hibernate.query.sqm.tree.predicate.SqmWhereClause.copy(SqmWhereClause.java:33)
at org.hibernate.query.sqm.tree.select.SqmQuerySpec.copy(SqmQuerySpec.java:107)
at org.hibernate.query.sqm.tree.select.SqmQuerySpec.copy(SqmQuerySpec.java:56)
at org.hibernate.query.sqm.tree.select.SqmSelectStatement.copy(SqmSelectStatement.java:131)
at org.hibernate.query.sqm.tree.select.SqmSelectStatement.copy(SqmSelectStatement.java:42)
at org.hibernate.query.sqm.internal.QuerySqmImpl.<init>(QuerySqmImpl.java:226)
at org.hibernate.internal.AbstractSharedSessionContract.createCriteriaQuery(AbstractSharedSessionContract.java:1343)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:1304)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:190)
at org.hibernate.bugs.JPAUnitTestCase.shouldQueryWhenTwoLevelsInHierarchy(JPAUnitTestCase.java:78)
The bug did not happen in 6.2.5, and it doesn’t happen when querying a direct subclass of the root Data entity (as shown in the attached repro)
( https://hibernate.atlassian.net/browse/HHH-16988#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16988#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=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100233- sha1:f5b6255 )
2 years, 5 months