diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/spi/NativeQueryTupleTransformer.java b/hibernate-core/src/main/java/org/hibernate/jpa/spi/NativeQueryTupleTransformer.java index 440082fc42..7634dd5a42 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/spi/NativeQueryTupleTransformer.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/spi/NativeQueryTupleTransformer.java @@ -60,6 +60,8 @@ public class NativeQueryTupleTransformer implements ResultTransformer, Ty private final Object[] tuple; + private final int size; + private final Map aliasToValue = new LinkedHashMap<>(); private final Map aliasReferences = new LinkedHashMap<>(); @@ -75,9 +77,13 @@ public class NativeQueryTupleTransformer implements ResultTransformer, Ty } this.tuple = tuple; for ( int i = 0; i < tuple.length; i++ ) { - aliasToValue.put( aliases[i], tuple[i] ); - aliasReferences.put( aliases[i].toLowerCase(), aliases[i] ); + final String alias = aliases[i]; + if ( alias != null ) { + aliasToValue.put( alias, tuple[i] ); + aliasReferences.put( alias.toLowerCase(), alias ); + } } + size = tuple.length; } @Override @@ -108,7 +114,7 @@ public class NativeQueryTupleTransformer implements ResultTransformer, Ty if ( i < 0 ) { throw new IllegalArgumentException( "requested tuple index must be greater than zero" ); } - if ( i >= aliasToValue.size() ) { + if ( i >= size ) { throw new IllegalArgumentException( "requested tuple index exceeds actual tuple size" ); } return tuple[i]; @@ -122,7 +128,7 @@ public class NativeQueryTupleTransformer implements ResultTransformer, Ty @Override public List> getElements() { - List> elements = new ArrayList<>( aliasToValue.size() ); + List> elements = new ArrayList<>( size ); for ( Map.Entry entry : aliasToValue.entrySet() ) { elements.add( new NativeTupleElementImpl<>( getValueClass( entry.getValue() ), entry.getKey() ) );