Uploaded image for project: 'Hibernate ORM'
  1. HHH-11897

Fix support for Tuple results for native queries

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.2.10
    • Fix Version/s: 5.2.11
    • Component/s: hibernate-core
    • Labels:
      None

      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:

      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:

      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]
      

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: