@@ -89,7 +89,7 @@ public Object convertDirectly(Object entityInstance) {
89
89
PersistentPropertyAccessor <Object > dtoAccessor = targetEntity .getPropertyAccessor (dto );
90
90
targetEntity .doWithProperties ((SimplePropertyHandler ) property -> {
91
91
92
- if (constructor .isConstructorParameter (property )) {
92
+ if (constructor != null && constructor .isConstructorParameter (property )) {
93
93
return ;
94
94
}
95
95
@@ -108,11 +108,14 @@ Object getPropertyValueDirectlyFor(PersistentProperty<?> targetProperty, Persist
108
108
String targetPropertyName = targetProperty .getName ();
109
109
PersistentProperty <?> sourceProperty = sourceEntity .getPersistentProperty (targetPropertyName );
110
110
111
+ if (sourceProperty == null ) {
112
+ return null ;
113
+ }
111
114
return sourceAccessor .getProperty (sourceProperty );
112
115
}
113
116
114
117
@ Override
115
- public Object convert (EntityInstanceWithSource entityInstanceAndSource ) {
118
+ public Object convert (@ Nullable EntityInstanceWithSource entityInstanceAndSource ) {
116
119
117
120
if (entityInstanceAndSource == null ) {
118
121
return null ;
@@ -126,7 +129,8 @@ public Object convert(EntityInstanceWithSource entityInstanceAndSource) {
126
129
Neo4jPersistentEntity <?> sourceEntity = context .getRequiredPersistentEntity (entityInstance .getClass ());
127
130
PersistentPropertyAccessor <Object > sourceAccessor = sourceEntity .getPropertyAccessor (entityInstance );
128
131
129
- Neo4jPersistentEntity <?> targetEntity = context .addPersistentEntity (ClassTypeInformation .from (targetType )).get ();
132
+ Neo4jPersistentEntity <?> targetEntity = context .addPersistentEntity (ClassTypeInformation .from (targetType ))
133
+ .orElseThrow (() -> new MappingException ("Could not add a persistent entity for the projection target type '" + targetType .getName () + "'." ));
130
134
PreferredConstructor <?, ? extends PersistentProperty <?>> constructor = targetEntity
131
135
.getPersistenceConstructor ();
132
136
@@ -146,7 +150,7 @@ public Object convert(EntityInstanceWithSource entityInstanceAndSource) {
146
150
147
151
private ParameterValueProvider <Neo4jPersistentProperty > getParameterValueProvider (
148
152
Neo4jPersistentEntity <?> targetEntity ,
149
- Function <PersistentProperty <?> , Object > extractFromSource
153
+ Function <Neo4jPersistentProperty , Object > extractFromSource
150
154
) {
151
155
return new ParameterValueProvider <Neo4jPersistentProperty >() {
152
156
@ SuppressWarnings ("unchecked" ) // Needed for the last cast. It's easier that way than using the parameter type info and checking for primivites
@@ -157,7 +161,7 @@ public <T> T getParameterValue(Parameter<T, Neo4jPersistentProperty> parameter)
157
161
throw new MappingException (
158
162
"Constructor parameter names aren't available, please recompile your domain." );
159
163
}
160
- PersistentProperty <?> targetProperty = targetEntity .getPersistentProperty (parameterName );
164
+ Neo4jPersistentProperty targetProperty = targetEntity .getPersistentProperty (parameterName );
161
165
if (targetProperty == null ) {
162
166
throw new MappingException ("Cannot map constructor parameter " + parameterName
163
167
+ " to a property of class " + targetType );
@@ -168,10 +172,10 @@ public <T> T getParameterValue(Parameter<T, Neo4jPersistentProperty> parameter)
168
172
}
169
173
170
174
private void setPropertyOnDtoObject (EntityInstanceWithSource entityInstanceAndSource , PersistentEntity <?, ?> sourceEntity ,
171
- PersistentPropertyAccessor <Object > sourceAccessor , PreferredConstructor <?, ?> constructor ,
172
- PersistentPropertyAccessor <Object > dtoAccessor , PersistentProperty <?> property ) {
175
+ PersistentPropertyAccessor <Object > sourceAccessor , @ Nullable PreferredConstructor <?, ?> constructor ,
176
+ PersistentPropertyAccessor <Object > dtoAccessor , Neo4jPersistentProperty property ) {
173
177
174
- if (constructor .isConstructorParameter (property )) {
178
+ if (constructor != null && constructor .isConstructorParameter (property )) {
175
179
return ;
176
180
}
177
181
@@ -180,7 +184,7 @@ private void setPropertyOnDtoObject(EntityInstanceWithSource entityInstanceAndSo
180
184
}
181
185
182
186
@ Nullable
183
- Object getPropertyValueFor (PersistentProperty <?> targetProperty , PersistentEntity <?, ?> sourceEntity ,
187
+ Object getPropertyValueFor (Neo4jPersistentProperty targetProperty , PersistentEntity <?, ?> sourceEntity ,
184
188
PersistentPropertyAccessor <?> sourceAccessor , EntityInstanceWithSource entityInstanceAndSource ) {
185
189
186
190
TypeSystem typeSystem = entityInstanceAndSource .getTypeSystem ();
@@ -221,7 +225,7 @@ Object getPropertyValueFor(PersistentProperty<?> targetProperty, PersistentEntit
221
225
singleValue = p -> context .getEntityConverter ().read (actualType , p );
222
226
} else {
223
227
ClassTypeInformation <?> actualTargetType = ClassTypeInformation .from (actualType );
224
- singleValue = p -> context .getConversionService ().readValue (p , actualTargetType , null );
228
+ singleValue = p -> context .getConversionService ().readValue (p , actualTargetType , targetProperty . getOptionalReadingConverter () );
225
229
}
226
230
227
231
if (targetProperty .isCollectionLike ()) {
0 commit comments