24
24
import jakarta .persistence .criteria .CriteriaQuery ;
25
25
import jakarta .persistence .criteria .Expression ;
26
26
import jakarta .persistence .criteria .Predicate ;
27
+ import jakarta .persistence .metamodel .Attribute ;
27
28
import jakarta .persistence .metamodel .Bindable ;
28
29
import jakarta .persistence .metamodel .EntityType ;
29
30
import jakarta .persistence .metamodel .Metamodel ;
33
34
import java .util .Collection ;
34
35
import java .util .Iterator ;
35
36
import java .util .List ;
37
+ import java .util .stream .Collectors ;
36
38
37
39
import org .springframework .data .domain .Sort ;
38
40
import org .springframework .data .jpa .domain .JpaSort ;
@@ -215,12 +217,19 @@ private JpqlQueryBuilder.Select doSelect(Sort sort) {
215
217
216
218
if (returnedType .needsCustomConstruction ()) {
217
219
218
- Collection <String > requiredSelection = getRequiredSelection (sort , returnedType );
220
+ Collection <String > requiredSelection = null ;
221
+ if (returnedType .getReturnedType ().getPackageName ().startsWith ("java.util" )
222
+ || returnedType .getReturnedType ().getPackageName ().startsWith ("jakarta.persistence" )) {
223
+ requiredSelection = metamodel .managedType (returnedType .getDomainType ()).getAttributes ().stream ()
224
+ .map (Attribute ::getName ).collect (Collectors .toList ());
225
+ } else {
226
+ requiredSelection = getRequiredSelection (sort , returnedType );
227
+ }
219
228
220
229
List <PathAndOrigin > paths = new ArrayList <>(requiredSelection .size ());
221
230
for (String selection : requiredSelection ) {
222
- paths .add (
223
- JpqlUtils . toExpressionRecursively ( metamodel , entity , entityType , PropertyPath .from (selection , returnedType .getDomainType ()), true ));
231
+ paths .add (JpqlUtils . toExpressionRecursively ( metamodel , entity , entityType ,
232
+ PropertyPath .from (selection , returnedType .getDomainType ()), true ));
224
233
}
225
234
226
235
if (useTupleQuery ()) {
@@ -236,8 +245,8 @@ private JpqlQueryBuilder.Select doSelect(Sort sort) {
236
245
if (entityType .hasSingleIdAttribute ()) {
237
246
238
247
SingularAttribute <?, ?> id = entityType .getId (entityType .getIdType ().getJavaType ());
239
- return selectStep .select (
240
- JpqlUtils . toExpressionRecursively ( metamodel , entity , entityType , PropertyPath .from (id .getName (), returnedType .getDomainType ()), true ));
248
+ return selectStep .select (JpqlUtils . toExpressionRecursively ( metamodel , entity , entityType ,
249
+ PropertyPath .from (id .getName (), returnedType .getDomainType ()), true ));
241
250
242
251
} else {
243
252
0 commit comments