5151import org .hibernate .query .criteria .JpaCriteriaQuery ;
5252import org .hibernate .query .criteria .JpaRoot ;
5353import org .hibernate .query .hql .spi .SqmQueryImplementor ;
54- import org .hibernate .query .named .NamedResultSetMappingMemento ;
5554import org .hibernate .query .spi .HqlInterpretation ;
5655import org .hibernate .query .spi .QueryImplementor ;
57- import org .hibernate .query .sql .internal .NativeQueryImpl ;
5856import org .hibernate .query .sql .spi .NativeQueryImplementor ;
5957import org .hibernate .query .sqm .internal .SqmUtil ;
6058import org .hibernate .query .sqm .tree .SqmStatement ;
@@ -878,8 +876,7 @@ public <R> ReactiveNativeQueryImplementor<R> createReactiveNativeQuery(String sq
878876 delayedAfterCompletion ();
879877
880878 try {
881- ReactiveNativeQueryImpl <R > query = new ReactiveNativeQueryImpl <>( sqlString , this );
882-
879+ final ReactiveNativeQueryImpl <R > query = new ReactiveNativeQueryImpl <>( sqlString , this );
883880 if ( isEmpty ( query .getComment () ) ) {
884881 query .setComment ( "dynamic native SQL query" );
885882 }
@@ -893,17 +890,28 @@ public <R> ReactiveNativeQueryImplementor<R> createReactiveNativeQuery(String sq
893890
894891 @ Override
895892 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 ) {
897900 if ( Tuple .class .equals ( resultClass ) ) {
898- query .setTupleTransformer ( new NativeQueryTupleTransformer () );
901+ query .setTupleTransformer ( NativeQueryTupleTransformer . INSTANCE );
899902 }
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+ // }
900909 else if ( getFactory ().getMappingMetamodel ().isEntityClass ( resultClass ) ) {
901910 query .addEntity ( "alias1" , resultClass .getName (), LockMode .READ );
902911 }
903- else {
904- ( ( NativeQueryImpl <?>) query ). addScalar ( 1 , resultClass );
912+ else if ( resultClass != Object . class && resultClass != Object []. class ) {
913+ query . addResultTypeClass ( resultClass );
905914 }
906- return query ;
907915 }
908916
909917 @ Override
@@ -912,12 +920,13 @@ public <R> ReactiveNativeQuery<R> createReactiveNativeQuery(
912920 Class <R > resultClass ,
913921 String tableAlias ) {
914922 final ReactiveNativeQuery <R > query = createReactiveNativeQuery ( sqlString );
915- if ( getFactory ().getMappingMetamodel ().isEntityClass (resultClass ) ) {
923+ if ( getFactory ().getMappingMetamodel ().isEntityClass ( resultClass ) ) {
916924 query .addEntity ( tableAlias , resultClass .getName (), LockMode .READ );
917925 return query ;
918926 }
919-
920- throw new UnknownEntityTypeException ( "unable to locate persister: " + resultClass .getName () );
927+ else {
928+ throw new UnknownEntityTypeException ( "unable to locate persister: " + resultClass .getName () );
929+ }
921930 }
922931
923932 @ Override
@@ -927,19 +936,9 @@ public <R> ReactiveNativeQuery<R> createReactiveNativeQuery(String sqlString, St
927936 delayedAfterCompletion ();
928937
929938 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 );
943942 //TODO: why no applyQuerySettingsAndHints( query ); ???
944943 }
945944 catch (RuntimeException he ) {
@@ -1097,20 +1096,7 @@ public <R> ReactiveNativeQuery<R> createReactiveNativeQuery(
10971096 Class <R > resultType ,
10981097 AffectedEntities affectedEntities ) {
10991098 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 );
11141100 return query ;
11151101 }
11161102
0 commit comments