[JIRA] (HHH-16023) ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
by Fred (JIRA)
Fred ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=63be69f... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYjUwMDNiNjky... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16023?atlOrigin=eyJpIjoiYjUwMD... ) HHH-16023 ( https://hibernate.atlassian.net/browse/HHH-16023?atlOrigin=eyJpIjoiYjUwMD... ) ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1 ( https://hibernate.atlassian.net/browse/HHH-16023?atlOrigin=eyJpIjoiYjUwMD... )
Issue Type: Bug Affects Versions: 6.1.6 Assignee: Unassigned Components: hibernate-core Created: 11/Jan/2023 05:25 AM Priority: Major Reporter: Fred ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=63be69f... )
I’m migrating an application from Hibernate 5.6.14 to 6.1.6 and I encounter issues with the migration of some queries.
The original query involving many entities, it has been simplified to the following one for testing purpose :
@NamedNativeQueries(value = {
@NamedNativeQuery(
name = "MyEntity.findMyEntity",
query = """
WITH RECURSIVE all_my_entities AS (
SELECT me.* FROM my_entity me
)
SELECT {ame.*}
FROM all_my_entities ame
""")}
)
@Entity@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING, name = "catalog_item_type")
public class MyEntity<E extends MyEntity> {
@Id @GeneratedValue(generator = MY_SEQUENCE)
private Long id;
private String name;
}
Here is the simplified version of the repository :
@Repository
public class MyEntityRepository {
private final EntityManager entityManager;
public MyEntityRepository(EntityManager entityManager) {
this.entityManager = entityManager;
}
public Set<MyEntity> findMyEntities() {
Session session = entityManager.unwrap(Session.class);
List<MyEntity> myEntities = session.getNamedNativeQuery("MyEntity.findMyEntity")
.addEntity("ame", MyEntity.class)
.getResultList();
return new HashSet<>(myEntities);
}
}
I use the following test to reproduce the issue :
@SpringBootTest
public class TestApplicationTests {
@Autowired
private MyEntityRepository myEntityRepository;
@Test
public void shouldBuildNamedQuery() {
assertThat(myEntityRepository.findMyEntities()).isEmpty();
}
}
The above test succeeds with version Hibernate 5.6.14 (Springboot 2.7.7) and fails with Hibernate 6.1.6 (Springboot 3.0.1).
The test fails with the exception :
java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
at org.hibernate.persister.entity.AbstractEntityPersister.isSelectable(AbstractEntityPersister.java:2039)
at org.hibernate.persister.entity.AbstractEntityPersister.fetchProcessor(AbstractEntityPersister.java:2012)
at org.hibernate.loader.ast.internal.LoaderSqlAstCreationState.visitFetches(LoaderSqlAstCreationState.java:118)
at org.hibernate.sql.results.graph.AbstractFetchParent.afterInitialize(AbstractFetchParent.java:32)
at org.hibernate.sql.results.graph.entity.AbstractEntityResultGraphNode.afterInitialize(AbstractEntityResultGraphNode.java:100)
at org.hibernate.persister.entity.AbstractEntityPersister.createDomainResult(AbstractEntityPersister.java:1300)
at org.hibernate.persister.entity.AbstractEntityPersister.selectFragment(AbstractEntityPersister.java:1892)
at org.hibernate.query.sql.internal.SQLQueryParser.resolveProperties(SQLQueryParser.java:236)
at org.hibernate.query.sql.internal.SQLQueryParser.substituteBrackets(SQLQueryParser.java:159)
at org.hibernate.query.sql.internal.SQLQueryParser.process(SQLQueryParser.java:63)
at org.hibernate.query.sql.internal.NativeSelectQueryPlanImpl.<init>(NativeSelectQueryPlanImpl.java:54)
at org.hibernate.engine.query.internal.NativeQueryInterpreterStandardImpl.createQueryPlan(NativeQueryInterpreterStandardImpl.java:39)
at org.hibernate.query.sql.internal.NativeQueryImpl.createQueryPlan(NativeQueryImpl.java:649)
at org.hibernate.query.sql.internal.NativeQueryImpl.lambda$resolveSelectQueryPlan$7(NativeQueryImpl.java:610)
at org.hibernate.query.internal.QueryInterpretationCacheStandardImpl.resolveSelectQueryPlan(QueryInterpretationCacheStandardImpl.java:83)
at org.hibernate.query.sql.internal.NativeQueryImpl.resolveSelectQueryPlan(NativeQueryImpl.java:608)
at org.hibernate.query.sql.internal.NativeQueryImpl.doList(NativeQueryImpl.java:602)
at org.hibernate.query.spi.AbstractSelectionQuery.list(AbstractSelectionQuery.java:363)
at org.hibernate.query.Query.getResultList(Query.java:94)
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.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:401)
at jdk.proxy2/jdk.proxy2.$Proxy133.getResultList(Unknown Source)
at com.example.repository.CatalogItemRepository.findMyEntities(CatalogItemRepository.java:24)
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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:752)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:752)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:703)
at com.example.repository.CatalogItemRepository$$SpringCGLIB$$0.findMyEntities(<generated>)
at com.example.TestApplicationTests.shouldBuildNamedQuery(TestApplicationTests.java:22)
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.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
( https://hibernate.atlassian.net/browse/HHH-16023#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16023#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#100213- sha1:b01baad )
1 year, 11 months