[JIRA] (HHH-15661) ClassCastException in Select
by Arne Theß (JIRA)
Arne Theß ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=70121%3... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiOTQ4MTcyZTg2... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-15661?atlOrigin=eyJpIjoiOTQ4MT... ) HHH-15661 ( https://hibernate.atlassian.net/browse/HHH-15661?atlOrigin=eyJpIjoiOTQ4MT... ) ClassCastException in Select ( https://hibernate.atlassian.net/browse/HHH-15661?atlOrigin=eyJpIjoiOTQ4MT... )
Change By: Arne Theß ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=70121%3... )
We’re getting the following stack trace.
{{Caused by: java.lang.ClassCastException: class org.hibernate.type.CustomType cannot be cast to class org.hibernate.metamodel.mapping.EntityValuedModelPart (org.hibernate.type.CustomType and org.hibernate.metamodel.mapping.EntityValuedModelPart are in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @1162410a)}}
{{ at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitTableGroup(BaseSqmToSqlAstConverter.java:3481)}}
{{ at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitQualifiedAttributeJoin(BaseSqmToSqlAstConverter.java:3416)}}
{{ at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitQualifiedAttributeJoin(BaseSqmToSqlAstConverter.java:416)}}
{{ at org.hibernate.query.sqm.tree.domain.AbstractSqmAttributeJoin.accept(AbstractSqmAttributeJoin.java:131)}}
{{ at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitWithInferredType(BaseSqmToSqlAstConverter.java:6182)}}
{{ at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitIsNullPredicate(BaseSqmToSqlAstConverter.java:6686)}}
{{ at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitIsNullPredicate(BaseSqmToSqlAstConverter.java:416)}}
{{ at org.hibernate.query.sqm.tree.predicate.SqmNullnessPredicate.accept(SqmNullnessPredicate.java:53)}}
{{ at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitJunctionPredicate(BaseSqmToSqlAstConverter.java:6333)}}
{{ at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitJunctionPredicate(BaseSqmToSqlAstConverter.java:416)}}
{{ at org.hibernate.query.sqm.tree.predicate.SqmJunctionPredicate.accept(SqmJunctionPredicate.java:74)}}
{{ at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitWhereClause(BaseSqmToSqlAstConverter.java:2252)}}
{{ at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitQuerySpec(BaseSqmToSqlAstConverter.java:1823)}}
{{ at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitQuerySpec(BaseSqmToSqlAstConverter.java:416)}}
{{ at org.hibernate.query.sqm.tree.select.SqmQuerySpec.accept(SqmQuerySpec.java:122)}}
{{ at org.hibernate.query.sqm.spi.BaseSemanticQueryWalker.visitQueryPart(BaseSemanticQueryWalker.java:213)}}
{{ at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitQueryPart(BaseSqmToSqlAstConverter.java:1679)}}
{{ at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitSelectStatement(BaseSqmToSqlAstConverter.java:1477)}}
{{ at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitSelectStatement(BaseSqmToSqlAstConverter.java:416)}}
{{ at org.hibernate.query.sqm.tree.select.SqmSelectStatement.accept(SqmSelectStatement.java:199)}}
{{ at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.translate(BaseSqmToSqlAstConverter.java:711)}}
{{ at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.buildCacheableSqmInterpretation(ConcreteSqmSelectQueryPlan.java:350)}}
{{ at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.withCacheableSqmInterpretation(ConcreteSqmSelectQueryPlan.java:270)}}
{{ at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.performList(ConcreteSqmSelectQueryPlan.java:246)}}
{{ at org.hibernate.query.sqm.internal.QuerySqmImpl.doList(QuerySqmImpl.java:546)}}
{{ at org.hibernate.query.spi.AbstractSelectionQuery.list(AbstractSelectionQuery.java:363)}}
{{ at org.hibernate.query.sqm.internal.QuerySqmImpl.list(QuerySqmImpl.java:1032)}}
{{ at org.hibernate.query.Query.getResultList(Query.java:94)}}
The select worked fine in 6.1.1, but since upgrading to 6.1.5, we’re getting the class cast exception instead. I’m not quite sure, why. Similar selects are still working fine. Therefore I also don’t know how to construct a helpful test case.
( https://hibernate.atlassian.net/browse/HHH-15661#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-15661#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#100210- sha1:a51bb46 )
2 years, 2 months
[JIRA] (HHH-15658) Embeddable with more fields than the parent fails with Index out of Bounds
by Phil Haeusler (JIRA)
Phil Haeusler ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYjNkZWRjMzk1... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-15658?atlOrigin=eyJpIjoiYjNkZW... ) HHH-15658 ( https://hibernate.atlassian.net/browse/HHH-15658?atlOrigin=eyJpIjoiYjNkZW... ) Embeddable with more fields than the parent fails with Index out of Bounds ( https://hibernate.atlassian.net/browse/HHH-15658?atlOrigin=eyJpIjoiYjNkZW... )
Issue Type: Bug Affects Versions: 6.0.2, 6.1.0, 6.1.4, 6.1.5 Assignee: Unassigned Components: hibernate-core Created: 02/Nov/2022 17:36 PM Environment: Hibernate 6.1.5, Temurin 17.0.2, Mac, Postgres Priority: Blocker Reporter: Phil Haeusler ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
Use of @Embeddable class causes an unexpected index out of bounds before request is sent to the database. Given the follow scenario, a simple list() call was made to retrieve all entries.
@Entity
public class Person
{
private Address address;
}
@Embeddable
public class Address
{
private String city;
private String state;
private String country;
private String postcode;
}
The following exception occurs before a call is made to the database
java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2
at org.hibernate.persister.entity.SingleTableEntityPersister.getSubclassPropertyTableNumber(SingleTableEntityPersister.java:594) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.lambda$selectFragment$6(AbstractEntityPersister.java:1876) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at java.util.ArrayList.forEach(ArrayList.java:1511) ~[?:?]
at org.hibernate.metamodel.mapping.internal.EmbeddableMappingTypeImpl.visitAttributeMappings(EmbeddableMappingTypeImpl.java:726) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.metamodel.mapping.internal.EmbeddableMappingTypeImpl.visitSubParts(EmbeddableMappingTypeImpl.java:736) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping.visitSubParts(EmbeddedAttributeMapping.java:292) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.sql.results.graph.FetchableContainer.visitFetchables(FetchableContainer.java:35) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.lambda$selectFragment$7(AbstractEntityPersister.java:1862) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.loader.ast.internal.LoaderSqlAstCreationState.visitFetches(LoaderSqlAstCreationState.java:118) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.sql.results.graph.AbstractFetchParent.afterInitialize(AbstractFetchParent.java:32) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.sql.results.graph.embeddable.internal.EmbeddableFetchImpl.<init>(EmbeddableFetchImpl.java:75) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping.generateFetch(EmbeddedAttributeMapping.java:238) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.sql.results.graph.FetchParent.generateFetchableFetch(FetchParent.java:105) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.lambda$selectFragment$6(AbstractEntityPersister.java:1905) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at java.util.ArrayList.forEach(ArrayList.java:1511) ~[?:?]
at org.hibernate.persister.entity.AbstractEntityPersister.visitFetchables(AbstractEntityPersister.java:6699) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.lambda$selectFragment$7(AbstractEntityPersister.java:1862) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.loader.ast.internal.LoaderSqlAstCreationState.visitFetches(LoaderSqlAstCreationState.java:118) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.sql.results.graph.AbstractFetchParent.afterInitialize(AbstractFetchParent.java:32) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.sql.results.graph.entity.AbstractEntityResultGraphNode.afterInitialize(AbstractEntityResultGraphNode.java:100) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.createDomainResult(AbstractEntityPersister.java:1286) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.selectFragment(AbstractEntityPersister.java:1940) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.query.sql.internal.SQLQueryParser.resolveProperties(SQLQueryParser.java:236) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.query.sql.internal.SQLQueryParser.substituteBrackets(SQLQueryParser.java:159) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.query.sql.internal.SQLQueryParser.process(SQLQueryParser.java:63) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.query.sql.internal.NativeSelectQueryPlanImpl.<init>(NativeSelectQueryPlanImpl.java:53) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.engine.query.internal.NativeQueryInterpreterStandardImpl.createQueryPlan(NativeQueryInterpreterStandardImpl.java:39) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.query.sql.internal.NativeQueryImpl.createQueryPlan(NativeQueryImpl.java:643) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.query.sql.internal.NativeQueryImpl.lambda$resolveSelectQueryPlan$7(NativeQueryImpl.java:604) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.query.internal.QueryInterpretationCacheStandardImpl.resolveSelectQueryPlan(QueryInterpretationCacheStandardImpl.java:83) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.query.sql.internal.NativeQueryImpl.resolveSelectQueryPlan(NativeQueryImpl.java:602) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.query.sql.internal.NativeQueryImpl.doList(NativeQueryImpl.java:596) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at org.hibernate.query.spi.AbstractSelectionQuery.list(AbstractSelectionQuery.java:363) ~[hibernate-core-6.1.4.Final.jar:6.1.4.Final]
at TestRepository.getPerson(TestRepository.java:157) ~[test.jar:?]
The stack trace references the following code within Hibernate. When debugging, it was found it is invoked for each field of the Address Embeddable.
org.hibernate.persister.entity.AbstractEntityPersister#selectFragment(String alias, String suffix)
if ( fetchable instanceof AttributeMapping ) {
if ( fetchParent instanceof EmbeddableResultGraphNode && ( (EmbeddableResultGraphNode) fetchParent ).getReferencedMappingContainer() == getIdentifierMapping() ) {
selectable = true;
}
else {
final int propertyNumber = ( (AttributeMapping) fetchable ).getStateArrayPosition();
final int tableNumber = getSubclassPropertyTableNumber( propertyNumber );
selectable = !isSubclassTableSequentialSelect( tableNumber )
&& propertySelectable[propertyNumber];
}
}
In this segment of code, propertyNumber is defined to be the position of the field within the Address Embeddable. In the above Address example, this could be a value from 0 through 3.
Then tableNumber is retrieved using getSubclassPropertyTableNumber which defines only two entries, being the table reference for the Person and Address objects.
The bug seems to be using the position of the Embeddable field to retrieve the tab reference for the entity. When the number of fields in the embeddable exceeds the number of Embeddable entries in the parent object, the observed index out of bounds exception occurs.
( https://hibernate.atlassian.net/browse/HHH-15658#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-15658#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#100210- sha1:cad9577 )
2 years, 2 months