Named native queries do not work with {{jakarta.persistence.Tuple}} return class. E.g. calling {{entityManager.createNamedQuery("Demo.findAllCustom", Tuple.class);}} causes following NullPointerException:
{noformat}Cannot invoke "String.toLowerCase()" because "aliases[i]" is null java.lang.NullPointerException: Cannot invoke "String.toLowerCase()" because "aliases[i]" is null at org.hibernate.jpa.spi.NativeQueryTupleTransformer$NativeTupleImpl.<init>(NativeQueryTupleTransformer.java:79) at org.hibernate.jpa.spi.NativeQueryTupleTransformer.transformTuple(NativeQueryTupleTransformer.java:29) at org.hibernate.jpa.spi.NativeQueryTupleTransformer.transformTuple(NativeQueryTupleTransformer.java:25) at org.hibernate.sql.results.internal.RowTransformerTupleTransformerAdapter.transformRow(RowTransformerTupleTransformerAdapter.java:30) at org.hibernate.sql.results.internal.StandardRowReader.readRow(StandardRowReader.java:109) at org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:198) at org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:33) at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.doExecuteQuery(JdbcSelectExecutorStandardImpl.java:443) at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.executeQuery(JdbcSelectExecutorStandardImpl.java:166) at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.list(JdbcSelectExecutorStandardImpl.java:91) at org.hibernate.sql.exec.spi.JdbcSelectExecutor.list(JdbcSelectExecutor.java:31) at org.hibernate.query.sql.internal.NativeSelectQueryPlanImpl.performList(NativeSelectQueryPlanImpl.java:105) 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 com.example.demo.DemoApplicationTests.testNamedNativeQueries3(DemoApplicationTests.java:57){noformat}
Test case: [https://github.com/isaul32/spring-data-jpa-named-native-query-bug|https://github.com/isaul32/spring-data-jpa-named-native-query-bug|smart-link] Working test case (Hibernate 5): [https://github.com/isaul32/spring-data-jpa-named-native-query-bug/pull/1|https://github.com/isaul32/spring-data-jpa-named-native-query-bug/pull/1|smart-link] Spring Data JPA issue: [https://github.com/spring-projects/spring-data-jpa/issues/2779|https://github.com/spring-projects/spring-data-jpa/issues/2779|smart-link] |
|