Marco Belladelli (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=637b480...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZmI5MmU0ZDcx...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16014?atlOrigin=eyJpIjoiZmI5Mm...
) HHH-16014 (
https://hibernate.atlassian.net/browse/HHH-16014?atlOrigin=eyJpIjoiZmI5Mm...
) Querying property from treated path causes IllegalArgumentException: Already registered
a copy (
https://hibernate.atlassian.net/browse/HHH-16014?atlOrigin=eyJpIjoiZmI5Mm...
)
Issue Type: Bug Affects Versions: 6.1.6 Assignee: Marco Belladelli (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=637b480...
) Components: query-criteria Created: 10/Jan/2023 07:41 AM Priority: Major Reporter: Marco
Belladelli (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=637b480...
)
Querying a property of a Path created by the treat method causes an Exception to be
thrown. Here’s an example of a Criteria Query that triggers the problem:
Path<LocalTerm> asLocalTerm = cb.treat( root.get( "term" ),
LocalTerm.class );
criteria.select( root ).where( cb.equal( asLocalTerm.get( "property" ), value )
);
And here’s the stack trace:
java.lang.IllegalArgumentException: Already registered a copy:
SqmEntityValuedSimplePath(treat(org.hibernate.orm.test.jpa.criteria.TreatTablePerClassTest$Linkage(27365580293082).term
as org.hibernate.orm.test.jpa.criteria.TreatTablePerClassTest$LocalTerm).language)
at org.hibernate.query.sqm.tree.SqmCopyContext$1.registerCopy(SqmCopyContext.java:33)
at
org.hibernate.query.sqm.tree.domain.SqmEntityValuedSimplePath.copy(SqmEntityValuedSimplePath.java:37)
at
org.hibernate.query.sqm.tree.domain.SqmEntityValuedSimplePath.copy(SqmEntityValuedSimplePath.java:21)
at
org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate.copy(SqmComparisonPredicate.java:69)
at
org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate.copy(SqmComparisonPredicate.java:20)
at org.hibernate.query.sqm.tree.predicate.SqmWhereClause.copy(SqmWhereClause.java:33)
at org.hibernate.query.sqm.tree.select.SqmQuerySpec.copy(SqmQuerySpec.java:104)
at org.hibernate.query.sqm.tree.select.SqmQuerySpec.copy(SqmQuerySpec.java:53)
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:227)
at
org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:1295)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:181)
The issue appears to be caused by the copy method of the
treatedPath.get("property") object: here, the left-hand side, which is the
{{treat}}ed path, causes another copy of the property to be triggered while the first one
was still being processed and not registered.
(
https://hibernate.atlassian.net/browse/HHH-16014#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16014#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#100213- sha1:cca7326 )