Skip to content

Commit be71c0d

Browse files
committed
GH-2797 - Fetch current object's state from property accessor.
Before this change, the updated properties where ignored when there was a call to a wither function for property setting. Closes #2797
1 parent 0de0468 commit be71c0d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/main/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jEntityConverter.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)