@@ -80,7 +80,7 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements
80
80
* {@link #MappingJdbcConverter(RelationalMappingContext, RelationResolver, CustomConversions, JdbcTypeFactory)}
81
81
* (MappingContext, RelationResolver, JdbcTypeFactory)} to convert arrays and large objects into JDBC-specific types.
82
82
*
83
- * @param context must not be {@literal null}.
83
+ * @param context must not be {@literal null}.
84
84
* @param relationResolver used to fetch additional relations from the database. Must not be {@literal null}.
85
85
*/
86
86
public MappingJdbcConverter (RelationalMappingContext context , RelationResolver relationResolver ) {
@@ -98,12 +98,12 @@ public MappingJdbcConverter(RelationalMappingContext context, RelationResolver r
98
98
/**
99
99
* Creates a new {@link MappingJdbcConverter} given {@link MappingContext}.
100
100
*
101
- * @param context must not be {@literal null}.
101
+ * @param context must not be {@literal null}.
102
102
* @param relationResolver used to fetch additional relations from the database. Must not be {@literal null}.
103
- * @param typeFactory must not be {@literal null}
103
+ * @param typeFactory must not be {@literal null}
104
104
*/
105
105
public MappingJdbcConverter (RelationalMappingContext context , RelationResolver relationResolver ,
106
- CustomConversions conversions , JdbcTypeFactory typeFactory ) {
106
+ CustomConversions conversions , JdbcTypeFactory typeFactory ) {
107
107
108
108
super (context , conversions );
109
109
@@ -220,7 +220,7 @@ private boolean canWriteAsJdbcValue(@Nullable Object value) {
220
220
return true ;
221
221
}
222
222
223
- if (value instanceof AggregateReference aggregateReference ) {
223
+ if (value instanceof AggregateReference <?, ?> aggregateReference ) {
224
224
return canWriteAsJdbcValue (aggregateReference .getId ());
225
225
}
226
226
@@ -285,7 +285,7 @@ public <R> R readAndResolve(TypeInformation<R> type, RowDocument source, Identif
285
285
286
286
@ Override
287
287
protected RelationalPropertyValueProvider newValueProvider (RowDocumentAccessor documentAccessor ,
288
- ValueExpressionEvaluator evaluator , ConversionContext context ) {
288
+ ValueExpressionEvaluator evaluator , ConversionContext context ) {
289
289
290
290
if (context instanceof ResolvingConversionContext rcc ) {
291
291
@@ -314,7 +314,7 @@ class ResolvingRelationalPropertyValueProvider implements RelationalPropertyValu
314
314
private final Identifier identifier ;
315
315
316
316
private ResolvingRelationalPropertyValueProvider (AggregatePathValueProvider delegate , RowDocumentAccessor accessor ,
317
- ResolvingConversionContext context , Identifier identifier ) {
317
+ ResolvingConversionContext context , Identifier identifier ) {
318
318
319
319
AggregatePath path = context .aggregatePath ();
320
320
@@ -323,15 +323,15 @@ private ResolvingRelationalPropertyValueProvider(AggregatePathValueProvider dele
323
323
this .context = context ;
324
324
this .identifier = path .isEntity ()
325
325
? potentiallyAppendIdentifier (identifier , path .getRequiredLeafEntity (),
326
- property -> delegate .getValue (path .append (property )))
326
+ property -> delegate .getValue (path .append (property )))
327
327
: identifier ;
328
328
}
329
329
330
330
/**
331
331
* Conditionally append the identifier if the entity has an identifier property.
332
332
*/
333
333
static Identifier potentiallyAppendIdentifier (Identifier base , RelationalPersistentEntity <?> entity ,
334
- Function <RelationalPersistentProperty , Object > getter ) {
334
+ Function <RelationalPersistentProperty , Object > getter ) {
335
335
336
336
if (entity .hasIdProperty ()) {
337
337
@@ -361,24 +361,9 @@ public <T> T getPropertyValue(RelationalPersistentProperty property) {
361
361
362
362
if (property .isCollectionLike () || property .isMap ()) {
363
363
364
- Identifier identifierToUse = this .identifier ;
365
- AggregatePath idDefiningParentPath = aggregatePath .getIdDefiningParentPath ();
364
+ Identifier identifier = constructIdentifier (aggregatePath );
366
365
367
- // note that the idDefiningParentPath might not itself have an id property, but have a combination of back
368
- // references and possibly keys, that form an id
369
- if (idDefiningParentPath .hasIdProperty ()) {
370
-
371
- RelationalPersistentProperty identifier = idDefiningParentPath .getRequiredIdProperty ();
372
- AggregatePath idPath = idDefiningParentPath .append (identifier );
373
- Object value = delegate .getValue (idPath );
374
-
375
- Assert .state (value != null , "Identifier value must not be null at this point" );
376
-
377
- identifierToUse = Identifier .of (aggregatePath .getTableInfo ().reverseColumnInfo ().name (), value ,
378
- identifier .getActualType ());
379
- }
380
-
381
- Iterable <Object > allByPath = relationResolver .findAllByPath (identifierToUse ,
366
+ Iterable <Object > allByPath = relationResolver .findAllByPath (identifier ,
382
367
aggregatePath .getRequiredPersistentPropertyPath ());
383
368
384
369
if (property .isCollectionLike ()) {
@@ -403,6 +388,29 @@ public <T> T getPropertyValue(RelationalPersistentProperty property) {
403
388
return (T ) delegate .getValue (aggregatePath );
404
389
}
405
390
391
+ private Identifier constructIdentifier (AggregatePath aggregatePath ) {
392
+
393
+ Identifier identifierToUse = this .identifier ;
394
+ AggregatePath idDefiningParentPath = aggregatePath .getIdDefiningParentPath ();
395
+
396
+ // note that the idDefiningParentPath might not itself have an id property, but have a combination of back
397
+ // references and possibly keys, that form an id
398
+ if (idDefiningParentPath .hasIdProperty ()) {
399
+
400
+ RelationalPersistentProperty idProperty = idDefiningParentPath .getRequiredIdProperty ();
401
+ AggregatePath idPath = idProperty .isEntity () ? idDefiningParentPath .append (idProperty ) : idDefiningParentPath ;
402
+ Identifier [] buildingIdentifier = new Identifier [] { Identifier .empty () };
403
+ aggregatePath .getTableInfo ().reverseColumnInfos ().forEach ((ap , ci ) -> {
404
+
405
+ Object value = delegate .getValue (idPath .append (ap ));
406
+ buildingIdentifier [0 ] = buildingIdentifier [0 ].withPart (ci .name (), value ,
407
+ ap .getRequiredLeafProperty ().getActualType ());
408
+ });
409
+ identifierToUse = buildingIdentifier [0 ];
410
+ }
411
+ return identifierToUse ;
412
+ }
413
+
406
414
@ Override
407
415
public boolean hasValue (RelationalPersistentProperty property ) {
408
416
@@ -423,7 +431,7 @@ public boolean hasValue(RelationalPersistentProperty property) {
423
431
return delegate .hasValue (toUse );
424
432
}
425
433
426
- return delegate .hasValue (aggregatePath .getTableInfo ().reverseColumnInfo ().alias ());
434
+ return delegate .hasValue (aggregatePath .getTableInfo ().reverseColumnInfos (). any ().alias ());
427
435
}
428
436
429
437
return delegate .hasValue (aggregatePath );
@@ -449,7 +457,7 @@ public boolean hasNonEmptyValue(RelationalPersistentProperty property) {
449
457
return delegate .hasValue (toUse );
450
458
}
451
459
452
- return delegate .hasValue (aggregatePath .getTableInfo ().reverseColumnInfo ().alias ());
460
+ return delegate .hasValue (aggregatePath .getTableInfo ().reverseColumnInfos (). any ().alias ());
453
461
}
454
462
455
463
return delegate .hasNonEmptyValue (aggregatePath );
@@ -460,7 +468,7 @@ public RelationalPropertyValueProvider withContext(ConversionContext context) {
460
468
461
469
return context == this .context ? this
462
470
: new ResolvingRelationalPropertyValueProvider (delegate .withContext (context ), accessor ,
463
- (ResolvingConversionContext ) context , identifier );
471
+ (ResolvingConversionContext ) context , identifier );
464
472
}
465
473
}
466
474
@@ -472,7 +480,7 @@ public RelationalPropertyValueProvider withContext(ConversionContext context) {
472
480
* @param identifier
473
481
*/
474
482
private record ResolvingConversionContext (ConversionContext delegate , AggregatePath aggregatePath ,
475
- Identifier identifier ) implements ConversionContext {
483
+ Identifier identifier ) implements ConversionContext {
476
484
477
485
@ Override
478
486
public <S > S convert (Object source , TypeInformation <? extends S > typeHint ) {
0 commit comments