@@ -328,7 +328,7 @@ private <ET> ET map(MapAccessor queryResult, Neo4jPersistentEntity<ET> nodeDescr
328328
329329 populateProperties (queryResult , nodeDescription , internalId , instance , lastMappedEntity , relationshipsFromResult , nodesFromResult , false );
330330
331- PersistentPropertyAccessor <ET > propertyAccessor = concreteNodeDescription .getPropertyAccessor (instance );
331+ PersistentPropertyAccessor <ET > propertyAccessor = concreteNodeDescription .getPropertyAccessor (getMostCurrentInstance ( internalId , instance ) );
332332 ET bean = propertyAccessor .getBean ();
333333 bean = eventSupport .maybeCallAfterConvert (bean , concreteNodeDescription , queryResult );
334334
@@ -353,7 +353,13 @@ private <ET> ET map(MapAccessor queryResult, Neo4jPersistentEntity<ET> nodeDescr
353353 // because we cannot just create new instances
354354 populateProperties (queryResult , nodeDescription , internalId , mappedObject , lastMappedEntity , relationshipsFromResult , nodesFromResult , true );
355355 }
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 );
357363 }
358364
359365
@@ -388,7 +394,7 @@ private <ET> void populateProperties(MapAccessor queryResult, Neo4jPersistentEnt
388394 // in a cyclic graph / with bidirectional relationships, we could end up in a state in which we
389395 // reference the start again. Because it is getting still constructed, it won't be in the knownObjects
390396 // store unless we temporarily put it there.
391- knownObjects .storeObject (internalId , mappedObject );
397+ knownObjects .storeObject (internalId , propertyAccessor . getBean () );
392398
393399 AssociationHandlerSupport .of (concreteNodeDescription ).doWithAssociations (
394400 populateFrom (queryResult , nodeDescription , propertyAccessor , isConstructorParameter , objectAlreadyMapped , relationshipsFromResult , nodesFromResult ));
0 commit comments