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=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100210- sha1:cad9577 )