We're updating the issue view to help you get more done. 

Fix support for Tuple results for native queries

Description

We found two problems in the implementation that was done to support tuples on native query.

Related to:
https://hibernate.atlassian.net/browse/HHH-11176
https://github.com/hibernate/hibernate-orm/pull/1955

------------------------------------------------
Problem 1: It does not work with the stream method, as the following example,
em.createNativeQuery("select 1 as one, 2 as two", Tuple.class).stream().forEach(...);

Stack Trace:

1 2 3 4 5 6 7 8 9 10 org.hibernate.HibernateException: Got different size of tuples and aliases at org.hibernate.jpa.spi.NativeQueryTupleTransformer$NativeTupleImpl.<init>(NativeQueryTupleTransformer.java:55) ~[hibernate-core-5.2.11-SNAPSHOT.jar:5.2.11.SNAPSHOT] at org.hibernate.jpa.spi.NativeQueryTupleTransformer.transformTuple(NativeQueryTupleTransformer.java:22) ~[hibernate-core-5.2.11-SNAPSHOT.jar:5.2.11.SNAPSHOT] at org.hibernate.hql.internal.HolderInstantiator.instantiate(HolderInstantiator.java:75) ~[hibernate-core-5.2.11-SNAPSHOT.jar:5.2.11.SNAPSHOT] at org.hibernate.internal.ScrollableResultsImpl.prepareCurrentRow(ScrollableResultsImpl.java:206) ~[hibernate-core-5.2.11-SNAPSHOT.jar:5.2.11.SNAPSHOT] at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:100) ~[hibernate-core-5.2.11-SNAPSHOT.jar:5.2.11.SNAPSHOT] at org.hibernate.query.internal.ScrollableResultsIterator.hasNext(ScrollableResultsIterator.java:33) ~[hibernate-core-5.2.11-SNAPSHOT.jar:5.2.11.SNAPSHOT] at java.util.Iterator.forEachRemaining(Iterator.java:115) ~[na:1.8.0_131] at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) ~[na:1.8.0_131] at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580) ~[na:1.8.0_131]

------------------------------------------------
Problem 2: It breaks if the first row contain null values.

If the first row contains null values, it breaks (due to the getClass - https://github.com/galovics/hibernate-orm/blob/090ab4646ad1926f378e3f1608ffe900758b07d2/hibernate-core/src/main/java/org/hibernate/jpa/spi/NativeQueryTupleTransformer.java#L121 )

Stack Trace:

1 2 java.lang.NullPointerException: null at org.hibernate.jpa.spi.NativeQueryTupleTransformer$NativeTupleImpl.getElements(NativeQueryTupleTransformer.java:109) ~[hibernate-core-5.2.11-SNAPSHOT.jar:5.2.11.SNAPSHOT]

Environment

None

Status

Assignee

Vlad Mihalcea

Reporter

Tiago Jacobs

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

backportDecision

None

Components

Affects versions

5.2.10

Priority

Major