@@ -541,24 +541,25 @@ private Projection getProjection(Collection<SqlIdentifier> keyColumns, Query que
541
541
542
542
if (!CollectionUtils .isEmpty (query .getColumns ())) {
543
543
for (SqlIdentifier columnName : query .getColumns ()) {
544
- columns .add (Column .create (columnName , table ));
544
+
545
+ String columnNameString = columnName .getReference ();
546
+ RelationalPersistentProperty property = entity .getPersistentProperty (columnNameString );
547
+ if (property != null ) {
548
+
549
+ AggregatePath aggregatePath = mappingContext .getAggregatePath (
550
+ mappingContext .getPersistentPropertyPath (columnNameString , entity .getTypeInformation ()));
551
+ gatherColumn (aggregatePath , joins , columns );
552
+ } else {
553
+ columns .add (Column .create (columnName , table ));
554
+ }
545
555
}
546
556
} else {
547
557
for (PersistentPropertyPath <RelationalPersistentProperty > path : mappingContext
548
558
.findPersistentPropertyPaths (entity .getType (), p -> true )) {
549
559
550
- AggregatePath extPath = mappingContext .getAggregatePath (path );
560
+ AggregatePath aggregatePath = mappingContext .getAggregatePath (path );
551
561
552
- // add a join if necessary
553
- Join join = getJoin (extPath );
554
- if (join != null ) {
555
- joins .add (join );
556
- }
557
-
558
- Column column = getColumn (extPath );
559
- if (column != null ) {
560
- columns .add (column );
561
- }
562
+ gatherColumn (aggregatePath , joins , columns );
562
563
}
563
564
}
564
565
@@ -569,6 +570,20 @@ private Projection getProjection(Collection<SqlIdentifier> keyColumns, Query que
569
570
return new Projection (columns , joins );
570
571
}
571
572
573
+ private void gatherColumn (AggregatePath aggregatePath , Set <Join > joins , Set <Expression > columns ) {
574
+
575
+ // add a join if necessary
576
+ Join join = getJoin (aggregatePath );
577
+ if (join != null ) {
578
+ joins .add (join );
579
+ }
580
+
581
+ Column column = getColumn (aggregatePath );
582
+ if (column != null ) {
583
+ columns .add (column );
584
+ }
585
+ }
586
+
572
587
/**
573
588
* Projection including its source joins.
574
589
*
0 commit comments