From cd78afda8e75f02b63bd481e4c664e1fb8970614 Mon Sep 17 00:00:00 2001 From: Gerrit Meier Date: Tue, 24 Jan 2023 10:59:16 +0100 Subject: [PATCH] GH-2661 - Detect entity in projection correctly. There was a random picking of correct property paths if they represented the very same length (1). Added a `isEntity` filter to be sure that only the interesting property paths get returned. Closes #2661 --- .../data/neo4j/core/mapping/PropertyFilter.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/springframework/data/neo4j/core/mapping/PropertyFilter.java b/src/main/java/org/springframework/data/neo4j/core/mapping/PropertyFilter.java index 8ae33b248..7a1c32377 100644 --- a/src/main/java/org/springframework/data/neo4j/core/mapping/PropertyFilter.java +++ b/src/main/java/org/springframework/data/neo4j/core/mapping/PropertyFilter.java @@ -100,7 +100,9 @@ public abstract class PropertyFilter { } // create a sorted list of the deepest paths first - Optional candidate = projectingPropertyPaths.stream().map(pp -> pp.propertyPath.toDotPath()).sorted((o1, o2) -> { + Optional candidate = projectingPropertyPaths.stream() + .filter(pp -> pp.isEntity) + .map(pp -> pp.propertyPath.toDotPath()).sorted((o1, o2) -> { int depth1 = StringUtils.countOccurrencesOf(o1, "."); int depth2 = StringUtils.countOccurrencesOf(o2, "."); @@ -109,12 +111,9 @@ public abstract class PropertyFilter { .filter(d -> dotPath.contains(d) && dotPath.startsWith(d)) .findFirst(); - //noinspection OptionalGetWithoutIsPresent return projectingPropertyPaths.stream().map(pp -> pp.propertyPath.toDotPath()) .anyMatch(ppDotPath -> ppDotPath.equals(dotPath)) - || (dotPath.contains(".") && candidate.isPresent() && - projectingPropertyPaths.stream() - .filter(pp -> pp.propertyPath.toDotPath().equals(candidate.get())).findFirst().get().isEntity); + || (dotPath.contains(".") && candidate.isPresent()); } @Override