[JIRA] (HHH-15720) Using multiple select in a multiselect generates java.lang.ArrayIndexOutOfBoundsException
by Florent Marquier (JIRA)
Florent Marquier ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=6373676... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYmNmZDQ3YmJj... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-15720?atlOrigin=eyJpIjoiYmNmZD... ) HHH-15720 ( https://hibernate.atlassian.net/browse/HHH-15720?atlOrigin=eyJpIjoiYmNmZD... ) Using multiple select in a multiselect generates java.lang.ArrayIndexOutOfBoundsException ( https://hibernate.atlassian.net/browse/HHH-15720?atlOrigin=eyJpIjoiYmNmZD... )
Change By: Florent Marquier ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=6373676... )
Using any kind of entity this test will fail with java.lang.ArrayIndexOutOfBoundsException.
Full stack:
{code:java}
java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter$SqmAliasedNodePositionTracker.resolveSqlSelection(BaseSqmToSqlAstConverter.java:7356)
at org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl.resolveSqlSelection(BasicEntityIdentifierMappingImpl.java:275)
at org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl.createDomainResult(BasicEntityIdentifierMappingImpl.java:207)
at org.hibernate.query.sqm.sql.internal.AbstractSqmPathInterpretation.createDomainResult(AbstractSqmPathInterpretation.java:55)
at org.hibernate.sql.results.graph.instantiation.internal.DynamicInstantiationArgument.buildArgumentDomainResult(DynamicInstantiationArgument.java:37)
at org.hibernate.sql.results.graph.instantiation.internal.DynamicInstantiation.lambda$createDomainResult$0(DynamicInstantiation.java:106)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
at org.hibernate.sql.results.graph.instantiation.internal.DynamicInstantiation.createDomainResult(DynamicInstantiation.java:107)
at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.lambda$visitSelection$25(BaseSqmToSqlAstConverter.java:2063)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitSelection(BaseSqmToSqlAstConverter.java:2058)
at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitSelectClause(BaseSqmToSqlAstConverter.java:1961)
at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitQuerySpec(BaseSqmToSqlAstConverter.java:1829)
at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitQuerySpec(BaseSqmToSqlAstConverter.java:414)
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:1689)
at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitSelectStatement(BaseSqmToSqlAstConverter.java:1487)
at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitSelectStatement(BaseSqmToSqlAstConverter.java:414)
at org.hibernate.query.sqm.tree.select.SqmSelectStatement.accept(SqmSelectStatement.java:199)
at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.translate(BaseSqmToSqlAstConverter.java:709)
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)
at com.iterop.bpm.engine.impl.HibernateBug.testFail2ParamsOrder(HibernateBug.java:57)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
{code}
I tried to reduce reproduce with minimum code:
{code:java}
public class HibernateBug {
record R1(String a) {
}
record R2(String a, String b) {
}
@Test
public void testWorks1ParamOrder() {
try (EntityManagerFactory emf = RepositoryUtil.createEntityManagerFactory()) {
try (EntityManager em = emf.createEntityManager()) {
CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
CriteriaQuery<Tuple> critQuery = criteriaBuilder.createTupleQuery();
Root<TaskEntity> root = critQuery.from(TaskEntity.class);
critQuery.multiselect(criteriaBuilder.construct(R1.class, root.get("id")));
critQuery.orderBy(criteriaBuilder.asc(root.get("id")));
em.createQuery(critQuery).getResultList();
}
}
}
@Test
public void testWorks2ParamsNoOrder() {
try (EntityManagerFactory emf = RepositoryUtil.createEntityManagerFactory()) {
try (EntityManager em = emf.createEntityManager()) {
CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
CriteriaQuery<Tuple> critQuery = criteriaBuilder.createTupleQuery();
Root<TaskEntity> root = critQuery.from(TaskEntity.class);
critQuery.multiselect(criteriaBuilder.construct(R2.class, root.get("id"), root.get("id")));
em.createQuery(critQuery).getResultList();
}
}
}
@Test
public void testFail2ParamsOrder() {
try (EntityManagerFactory emf = RepositoryUtil.createEntityManagerFactory()) {
try (EntityManager em = emf.createEntityManager()) {
CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
CriteriaQuery<Tuple> critQuery = criteriaBuilder.createTupleQuery();
Root<TaskEntity> root = critQuery.from(TaskEntity.class);
critQuery.multiselect(criteriaBuilder.construct(R2.class, root.get("id"), root.get("id")));
critQuery.orderBy(criteriaBuilder.asc(root.get("id")));
em.createQuery(critQuery).getResultList();
}
}
}
}
{code}
( https://hibernate.atlassian.net/browse/HHH-15720#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-15720#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:28a3636 )