41
41
import org .springframework .data .mapping .PersistentPropertyAccessor ;
42
42
import org .springframework .data .mapping .PersistentPropertyPathAccessor ;
43
43
import org .springframework .data .mapping .context .MappingContext ;
44
- import org .springframework .data .mapping .model .ConvertingPropertyAccessor ;
45
- import org .springframework .data .mapping .model .DefaultSpELExpressionEvaluator ;
46
- import org .springframework .data .mapping .model .EntityInstantiator ;
47
- import org .springframework .data .mapping .model .ParameterValueProvider ;
48
- import org .springframework .data .mapping .model .PersistentEntityParameterValueProvider ;
49
- import org .springframework .data .mapping .model .PropertyValueProvider ;
50
- import org .springframework .data .mapping .model .SimpleTypeHolder ;
51
- import org .springframework .data .mapping .model .SpELContext ;
52
- import org .springframework .data .mapping .model .SpELExpressionEvaluator ;
53
- import org .springframework .data .mapping .model .SpELExpressionParameterValueProvider ;
44
+ import org .springframework .data .mapping .model .*;
54
45
import org .springframework .data .projection .EntityProjection ;
55
46
import org .springframework .data .projection .EntityProjectionIntrospector ;
56
47
import org .springframework .data .projection .EntityProjectionIntrospector .ProjectionPredicate ;
@@ -307,7 +298,7 @@ protected <S> S read(TypeInformation<S> type, RowDocument source) {
307
298
* @return the converted object, will never be {@literal null}.
308
299
*/
309
300
protected <S > S readAggregate (ConversionContext context , RowDocument document ,
310
- TypeInformation <? extends S > typeHint ) {
301
+ TypeInformation <? extends S > typeHint ) {
311
302
return readAggregate (context , new RowDocumentAccessor (document ), typeHint );
312
303
}
313
304
@@ -321,7 +312,7 @@ protected <S> S readAggregate(ConversionContext context, RowDocument document,
321
312
*/
322
313
@ SuppressWarnings ("unchecked" )
323
314
protected <S > S readAggregate (ConversionContext context , RowDocumentAccessor documentAccessor ,
324
- TypeInformation <? extends S > typeHint ) {
315
+ TypeInformation <? extends S > typeHint ) {
325
316
326
317
Class <? extends S > rawType = typeHint .getType ();
327
318
@@ -430,8 +421,7 @@ private <T> T doConvert(Object value, Class<? extends T> target) {
430
421
}
431
422
432
423
@ SuppressWarnings ("ConstantConditions" )
433
- private <T > T doConvert (Object value , Class <? extends T > target ,
434
- @ Nullable Class <? extends T > fallback ) {
424
+ private <T > T doConvert (Object value , Class <? extends T > target , @ Nullable Class <? extends T > fallback ) {
435
425
436
426
if (getConversionService ().canConvert (value .getClass (), target ) || fallback == null ) {
437
427
return getConversionService ().convert (value , target );
@@ -504,7 +494,7 @@ public RelationalPropertyValueProvider withContext(ConversionContext context) {
504
494
entity , contextualizing , context .getPath ().getCurrentObject ());
505
495
506
496
return new ConverterAwareSpELExpressionParameterValueProvider (context , evaluator , getConversionService (),
507
- new ConvertingParameterValueProvider <>( parameterProvider ::getParameterValue ));
497
+ new ConvertingParameterValueProvider <>(parameterProvider ::getParameterValue ));
508
498
}
509
499
510
500
private <S > S populateProperties (ConversionContext context , RelationalPersistentEntity <S > entity ,
@@ -562,15 +552,16 @@ private Object readEmbedded(ConversionContext conversionContext, RelationalPrope
562
552
RowDocumentAccessor source , RelationalPersistentProperty property ,
563
553
RelationalPersistentEntity <?> persistentEntity ) {
564
554
565
- if (shouldReadEmbeddable (conversionContext , property , persistentEntity , provider )) {
555
+ if (shouldReadEmbeddable (conversionContext , property , persistentEntity , provider , source )) {
566
556
return read (conversionContext , persistentEntity , source );
567
557
}
568
558
569
559
return null ;
570
560
}
571
561
572
562
private boolean shouldReadEmbeddable (ConversionContext context , RelationalPersistentProperty property ,
573
- RelationalPersistentEntity <?> unwrappedEntity , RelationalPropertyValueProvider propertyValueProvider ) {
563
+ RelationalPersistentEntity <?> unwrappedEntity , RelationalPropertyValueProvider propertyValueProvider ,
564
+ RowDocumentAccessor source ) {
574
565
575
566
OnEmpty onEmpty = property .getRequiredAnnotation (Embedded .class ).onEmpty ();
576
567
@@ -580,8 +571,19 @@ private boolean shouldReadEmbeddable(ConversionContext context, RelationalPersis
580
571
581
572
for (RelationalPersistentProperty persistentProperty : unwrappedEntity ) {
582
573
583
- RelationalPropertyValueProvider contextual = propertyValueProvider
584
- .withContext (context .forProperty (persistentProperty ));
574
+ ConversionContext nestedContext = context .forProperty (persistentProperty );
575
+ RelationalPropertyValueProvider contextual = propertyValueProvider .withContext (nestedContext );
576
+
577
+ if (persistentProperty .isEmbedded ()) {
578
+
579
+ TypeInformation <?> typeInformation = persistentProperty .getTypeInformation ();
580
+
581
+ RelationalPersistentEntity <?> nestedEntity = getMappingContext ().getPersistentEntity (typeInformation );
582
+
583
+ if (readEmbedded (nestedContext , contextual , source , persistentProperty , nestedEntity ) != null ) {
584
+ return true ;
585
+ }
586
+ }
585
587
586
588
if (contextual .hasValue (persistentProperty )) {
587
589
return true ;
@@ -787,8 +789,7 @@ protected DefaultConversionContext(RelationalConverter sourceConverter,
787
789
788
790
@ SuppressWarnings ("unchecked" )
789
791
@ Override
790
- public <S > S convert (Object source , TypeInformation <? extends S > typeHint ,
791
- ConversionContext context ) {
792
+ public <S > S convert (Object source , TypeInformation <? extends S > typeHint , ConversionContext context ) {
792
793
793
794
Assert .notNull (source , "Source must not be null" );
794
795
Assert .notNull (typeHint , "TypeInformation must not be null" );
@@ -1196,7 +1197,7 @@ protected <T> T potentiallyConvertSpelValue(Object object, Parameter<T, Relation
1196
1197
}
1197
1198
}
1198
1199
1199
- private record PropertyTranslatingPropertyAccessor <T > (PersistentPropertyAccessor <T > delegate ,
1200
+ private record PropertyTranslatingPropertyAccessor <T >(PersistentPropertyAccessor <T > delegate ,
1200
1201
PersistentPropertyTranslator propertyTranslator ) implements PersistentPropertyAccessor <T > {
1201
1202
1202
1203
static <T > PersistentPropertyAccessor <T > create (PersistentPropertyAccessor <T > delegate ,
0 commit comments