@@ -328,7 +328,7 @@ private <ET> ET map(MapAccessor queryResult, Neo4jPersistentEntity<ET> nodeDescr
328
328
329
329
populateProperties (queryResult , nodeDescription , internalId , instance , lastMappedEntity , relationshipsFromResult , nodesFromResult , false );
330
330
331
- PersistentPropertyAccessor <ET > propertyAccessor = concreteNodeDescription .getPropertyAccessor (instance );
331
+ PersistentPropertyAccessor <ET > propertyAccessor = concreteNodeDescription .getPropertyAccessor (getMostCurrentInstance ( internalId , instance ) );
332
332
ET bean = propertyAccessor .getBean ();
333
333
bean = eventSupport .maybeCallAfterConvert (bean , concreteNodeDescription , queryResult );
334
334
@@ -353,7 +353,13 @@ private <ET> ET map(MapAccessor queryResult, Neo4jPersistentEntity<ET> nodeDescr
353
353
// because we cannot just create new instances
354
354
populateProperties (queryResult , nodeDescription , internalId , mappedObject , lastMappedEntity , relationshipsFromResult , nodesFromResult , true );
355
355
}
356
- return mappedObject ;
356
+ // due to a needed side effect in `populateProperties`, the entity might have been changed
357
+ return getMostCurrentInstance (internalId , mappedObject );
358
+ }
359
+
360
+ @ Nullable
361
+ private <ET > ET getMostCurrentInstance (String internalId , ET fallbackInstance ) {
362
+ return (ET ) (knownObjects .getObject (internalId ) != null ? knownObjects .getObject (internalId ) : fallbackInstance );
357
363
}
358
364
359
365
@@ -388,7 +394,7 @@ private <ET> void populateProperties(MapAccessor queryResult, Neo4jPersistentEnt
388
394
// in a cyclic graph / with bidirectional relationships, we could end up in a state in which we
389
395
// reference the start again. Because it is getting still constructed, it won't be in the knownObjects
390
396
// store unless we temporarily put it there.
391
- knownObjects .storeObject (internalId , mappedObject );
397
+ knownObjects .storeObject (internalId , propertyAccessor . getBean () );
392
398
393
399
AssociationHandlerSupport .of (concreteNodeDescription ).doWithAssociations (
394
400
populateFrom (queryResult , nodeDescription , propertyAccessor , isConstructorParameter , objectAlreadyMapped , relationshipsFromResult , nodesFromResult ));
0 commit comments