51
51
import org .hibernate .query .criteria .JpaCriteriaQuery ;
52
52
import org .hibernate .query .criteria .JpaRoot ;
53
53
import org .hibernate .query .hql .spi .SqmQueryImplementor ;
54
- import org .hibernate .query .named .NamedResultSetMappingMemento ;
55
54
import org .hibernate .query .spi .HqlInterpretation ;
56
55
import org .hibernate .query .spi .QueryImplementor ;
57
- import org .hibernate .query .sql .internal .NativeQueryImpl ;
58
56
import org .hibernate .query .sql .spi .NativeQueryImplementor ;
59
57
import org .hibernate .query .sqm .internal .SqmUtil ;
60
58
import org .hibernate .query .sqm .tree .SqmStatement ;
@@ -878,8 +876,7 @@ public <R> ReactiveNativeQueryImplementor<R> createReactiveNativeQuery(String sq
878
876
delayedAfterCompletion ();
879
877
880
878
try {
881
- ReactiveNativeQueryImpl <R > query = new ReactiveNativeQueryImpl <>( sqlString , this );
882
-
879
+ final ReactiveNativeQueryImpl <R > query = new ReactiveNativeQueryImpl <>( sqlString , this );
883
880
if ( isEmpty ( query .getComment () ) ) {
884
881
query .setComment ( "dynamic native SQL query" );
885
882
}
@@ -893,17 +890,28 @@ public <R> ReactiveNativeQueryImplementor<R> createReactiveNativeQuery(String sq
893
890
894
891
@ Override
895
892
public <R > ReactiveNativeQuery <R > createReactiveNativeQuery (String sqlString , Class <R > resultClass ) {
896
- ReactiveNativeQuery <R > query = createReactiveNativeQuery ( sqlString );
893
+ final ReactiveNativeQuery <R > query = createReactiveNativeQuery ( sqlString );
894
+ setTupleTransformerForResultType ( resultClass , query );
895
+ return query ;
896
+ }
897
+
898
+ // see AbstractSharedSessionContract.setTupleTransformerForResultType
899
+ private <R > void setTupleTransformerForResultType (Class <R > resultClass , ReactiveNativeQuery <R > query ) {
897
900
if ( Tuple .class .equals ( resultClass ) ) {
898
- query .setTupleTransformer ( new NativeQueryTupleTransformer () );
901
+ query .setTupleTransformer ( NativeQueryTupleTransformer . INSTANCE );
899
902
}
903
+ // else if ( Map.class.equals( resultClass ) ) {
904
+ // query.setTupleTransformer( NativeQueryMapTransformer.INSTANCE );
905
+ // }
906
+ // else if ( List.class.equals( resultClass ) ) {
907
+ // query.setTupleTransformer( NativeQueryListTransformer.INSTANCE );
908
+ // }
900
909
else if ( getFactory ().getMappingMetamodel ().isEntityClass ( resultClass ) ) {
901
910
query .addEntity ( "alias1" , resultClass .getName (), LockMode .READ );
902
911
}
903
- else {
904
- ( ( NativeQueryImpl <?>) query ). addScalar ( 1 , resultClass );
912
+ else if ( resultClass != Object . class && resultClass != Object []. class ) {
913
+ query . addResultTypeClass ( resultClass );
905
914
}
906
- return query ;
907
915
}
908
916
909
917
@ Override
@@ -912,12 +920,13 @@ public <R> ReactiveNativeQuery<R> createReactiveNativeQuery(
912
920
Class <R > resultClass ,
913
921
String tableAlias ) {
914
922
final ReactiveNativeQuery <R > query = createReactiveNativeQuery ( sqlString );
915
- if ( getFactory ().getMappingMetamodel ().isEntityClass (resultClass ) ) {
923
+ if ( getFactory ().getMappingMetamodel ().isEntityClass ( resultClass ) ) {
916
924
query .addEntity ( tableAlias , resultClass .getName (), LockMode .READ );
917
925
return query ;
918
926
}
919
-
920
- throw new UnknownEntityTypeException ( "unable to locate persister: " + resultClass .getName () );
927
+ else {
928
+ throw new UnknownEntityTypeException ( "unable to locate persister: " + resultClass .getName () );
929
+ }
921
930
}
922
931
923
932
@ Override
@@ -927,19 +936,9 @@ public <R> ReactiveNativeQuery<R> createReactiveNativeQuery(String sqlString, St
927
936
delayedAfterCompletion ();
928
937
929
938
try {
930
- if ( isNotEmpty ( resultSetMappingName ) ) {
931
- final NamedResultSetMappingMemento resultSetMappingMemento = getFactory ().getQueryEngine ()
932
- .getNamedObjectRepository ()
933
- .getResultSetMappingMemento ( resultSetMappingName );
934
-
935
- if ( resultSetMappingMemento == null ) {
936
- throw new HibernateException ( "Could not resolve specified result-set mapping name : " + resultSetMappingName );
937
- }
938
- return new ReactiveNativeQueryImpl <>( sqlString , resultSetMappingMemento , this );
939
- }
940
- else {
941
- return new ReactiveNativeQueryImpl <>( sqlString , this );
942
- }
939
+ return isNotEmpty ( resultSetMappingName )
940
+ ? new ReactiveNativeQueryImpl <>( sqlString , getResultSetMappingMemento ( resultSetMappingName ), this )
941
+ : new ReactiveNativeQueryImpl <>( sqlString , this );
943
942
//TODO: why no applyQuerySettingsAndHints( query ); ???
944
943
}
945
944
catch (RuntimeException he ) {
@@ -1097,20 +1096,7 @@ public <R> ReactiveNativeQuery<R> createReactiveNativeQuery(
1097
1096
Class <R > resultType ,
1098
1097
AffectedEntities affectedEntities ) {
1099
1098
final ReactiveNativeQuery <R > query = createReactiveNativeQuery ( queryString , affectedEntities );
1100
- return addResultType ( resultType , query );
1101
- }
1102
-
1103
- //TODO: copy/paste from ORM, change visibility
1104
- private <T > ReactiveNativeQuery <T > addResultType (Class <T > resultClass , ReactiveNativeQuery <T > query ) {
1105
- if ( Tuple .class .equals ( resultClass ) ) {
1106
- query .setTupleTransformer ( new NativeQueryTupleTransformer () );
1107
- }
1108
- else if ( getFactory ().getMappingMetamodel ().isEntityClass ( resultClass ) ) {
1109
- query .addEntity ( "alias1" , resultClass .getName (), LockMode .READ );
1110
- }
1111
- else if ( resultClass != Object .class && resultClass != Object [].class ) {
1112
- query .addScalar ( 1 , resultClass );
1113
- }
1099
+ setTupleTransformerForResultType ( resultType , query );
1114
1100
return query ;
1115
1101
}
1116
1102
0 commit comments