Skip to content

Commit 388c34e

Browse files
beikovmbladel
authored andcommitted
Don't change result type of criteria query when changing select clause
1 parent e64b112 commit 388c34e

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

hibernate-core/src/main/java/org/hibernate/query/sqm/internal/ConcreteSqmSelectQueryPlan.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ protected static <T> RowTransformer<T> determineRowTransformer(
176176
return makeRowTransformerTupleTransformerAdapter( sqm, queryOptions );
177177
}
178178

179-
if ( resultType == null ) {
179+
if ( resultType == null || resultType == Object.class ) {
180180
return RowTransformerStandardImpl.instance();
181181
}
182182

hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/AbstractSqmSelectQuery.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public abstract class AbstractSqmSelectQuery<T>
4646
implements SqmSelectQuery<T> {
4747
private final Map<String, SqmCteStatement<?>> cteStatements;
4848
private SqmQueryPart<T> sqmQueryPart;
49-
private Class<T> resultType;
49+
private final Class<T> resultType;
5050

5151
public AbstractSqmSelectQuery(Class<T> resultType, NodeBuilder builder) {
5252
this( new SqmQuerySpec<>( builder ), resultType, builder );
@@ -189,7 +189,7 @@ public Class<T> getResultType() {
189189
}
190190

191191
protected void setResultType(Class<T> resultType) {
192-
this.resultType = resultType;
192+
// No-op
193193
}
194194

195195
@Override
@@ -392,7 +392,6 @@ protected Selection<? extends T> getResultSelection(Selection<?>[] selections) {
392392
break;
393393
}
394394
default: {
395-
setResultType( (Class<T>) Object[].class );
396395
resultSelection = ( Selection<? extends T> ) nodeBuilder().array( selections );
397396
}
398397
}

hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSelectStatement.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ public SqmSelectStatement<T> copy(SqmCopyContext context) {
108108
if ( existing != null ) {
109109
return existing;
110110
}
111+
return createCopy( context, getResultType() );
112+
}
113+
114+
private <X> SqmSelectStatement<X> createCopy(SqmCopyContext context, Class<X> resultType) {
111115
final Set<SqmParameter<?>> parameters;
112116
if ( this.parameters == null ) {
113117
parameters = null;
@@ -118,17 +122,19 @@ public SqmSelectStatement<T> copy(SqmCopyContext context) {
118122
parameters.add( parameter.copy( context ) );
119123
}
120124
}
121-
final SqmSelectStatement<T> statement = context.registerCopy(
125+
//noinspection unchecked
126+
final SqmSelectStatement<X> statement = (SqmSelectStatement<X>) context.registerCopy(
122127
this,
123128
new SqmSelectStatement<>(
124129
nodeBuilder(),
125130
copyCteStatements( context ),
126-
getResultType(),
131+
resultType,
127132
getQuerySource(),
128133
parameters
129134
)
130135
);
131-
statement.setQueryPart( getQueryPart().copy( context ) );
136+
//noinspection unchecked
137+
statement.setQueryPart( (SqmQueryPart<X>) getQueryPart().copy( context ) );
132138
return statement;
133139
}
134140

@@ -262,9 +268,6 @@ public SqmSelectStatement<T> select(Selection<? extends T> selection) {
262268
checkSelectionIsJpaCompliant( selection );
263269
}
264270
getQuerySpec().setSelection( (JpaSelection<T>) selection );
265-
if ( getResultType() == Object.class ) {
266-
setResultType( (Class<T>) selection.getJavaType() );
267-
}
268271
return this;
269272
}
270273

@@ -306,7 +309,6 @@ public SqmSelectStatement<T> multiselect(List<Selection<?>> selectionList) {
306309
break;
307310
}
308311
default: {
309-
setResultType( (Class<T>) Object[].class );
310312
resultSelection = ( Selection<? extends T> ) nodeBuilder().array( selections );
311313
}
312314
}

hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSubQuery.java

-2
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ public SqmSubQuery<T> multiselect(List<Selection<?>> selectionList) {
241241
break;
242242
}
243243
default: {
244-
setResultType( (Class<T>) Object[].class );
245244
resultSelection = ( Selection<? extends T> ) nodeBuilder().array( selections );
246245
}
247246
}
@@ -580,7 +579,6 @@ public SqmExpressible<T> getNodeType() {
580579
public void applyInferableType(SqmExpressible<?> type) {
581580
//noinspection unchecked
582581
this.expressibleType = (SqmExpressible<T>) type;
583-
setResultType( type == null ? null : expressibleType.getExpressibleJavaType().getJavaTypeClass() );
584582
}
585583

586584
private void applyInferableType(Class<T> type) {

0 commit comments

Comments
 (0)