|
33 | 33 | import org.springframework.data.mapping.PersistentPropertyAccessor;
|
34 | 34 | import org.springframework.data.mapping.PreferredConstructor;
|
35 | 35 | import org.springframework.data.mapping.PreferredConstructor.Parameter;
|
| 36 | +import org.springframework.data.mapping.SimpleAssociationHandler; |
36 | 37 | import org.springframework.data.mapping.SimplePropertyHandler;
|
37 | 38 | import org.springframework.data.mapping.model.ParameterValueProvider;
|
38 | 39 | import org.springframework.data.util.ClassTypeInformation;
|
@@ -105,19 +106,29 @@ public Object getParameterValue(Parameter parameter) {
|
105 | 106 | });
|
106 | 107 |
|
107 | 108 | PersistentPropertyAccessor<Object> dtoAccessor = targetEntity.getPropertyAccessor(dto);
|
108 |
| - targetEntity.doWithProperties((SimplePropertyHandler) property -> { |
| 109 | + targetEntity.doWithProperties((SimplePropertyHandler) property -> |
| 110 | + setPropertyOnDtoObject(entityInstanceAndSource, sourceEntity, sourceAccessor, constructor, dtoAccessor, property)); |
109 | 111 |
|
110 |
| - if (constructor.isConstructorParameter(property)) { |
111 |
| - return; |
112 |
| - } |
113 |
| - |
114 |
| - Object propertyValue = getPropertyValueFor(property, sourceEntity, sourceAccessor, entityInstanceAndSource); |
115 |
| - dtoAccessor.setProperty(property, propertyValue); |
| 112 | + targetEntity.doWithAssociations((SimpleAssociationHandler) association -> { |
| 113 | + PersistentProperty<?> property = association.getInverse(); |
| 114 | + setPropertyOnDtoObject(entityInstanceAndSource, sourceEntity, sourceAccessor, constructor, dtoAccessor, property); |
116 | 115 | });
|
117 | 116 |
|
118 | 117 | return dto;
|
119 | 118 | }
|
120 | 119 |
|
| 120 | + private void setPropertyOnDtoObject(EntityInstanceWithSource entityInstanceAndSource, PersistentEntity<?, ?> sourceEntity, |
| 121 | + PersistentPropertyAccessor<Object> sourceAccessor, PreferredConstructor<?, ?> constructor, |
| 122 | + PersistentPropertyAccessor<Object> dtoAccessor, PersistentProperty<?> property) { |
| 123 | + |
| 124 | + if (constructor.isConstructorParameter(property)) { |
| 125 | + return; |
| 126 | + } |
| 127 | + |
| 128 | + Object propertyValue = getPropertyValueFor(property, sourceEntity, sourceAccessor, entityInstanceAndSource); |
| 129 | + dtoAccessor.setProperty(property, propertyValue); |
| 130 | + } |
| 131 | + |
121 | 132 | @Nullable
|
122 | 133 | Object getPropertyValueFor(PersistentProperty<?> targetProperty, PersistentEntity<?, ?> sourceEntity,
|
123 | 134 | PersistentPropertyAccessor sourceAccessor, EntityInstanceWithSource entityInstanceAndSource) {
|
|
0 commit comments