Skip to content

Commit cb03fca

Browse files
committed
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
1 parent 71e3fd7 commit cb03fca

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ public boolean contains(String dotPath, Class<?> typeToCheck) {
100100
}
101101

102102
// create a sorted list of the deepest paths first
103-
Optional<String> candidate = projectingPropertyPaths.stream().map(pp -> pp.propertyPath.toDotPath()).sorted((o1, o2) -> {
103+
Optional<String> candidate = projectingPropertyPaths.stream()
104+
.filter(pp -> pp.isEntity)
105+
.map(pp -> pp.propertyPath.toDotPath()).sorted((o1, o2) -> {
104106
int depth1 = StringUtils.countOccurrencesOf(o1, ".");
105107
int depth2 = StringUtils.countOccurrencesOf(o2, ".");
106108

@@ -109,12 +111,9 @@ public boolean contains(String dotPath, Class<?> typeToCheck) {
109111
.filter(d -> dotPath.contains(d) && dotPath.startsWith(d))
110112
.findFirst();
111113

112-
//noinspection OptionalGetWithoutIsPresent
113114
return projectingPropertyPaths.stream().map(pp -> pp.propertyPath.toDotPath())
114115
.anyMatch(ppDotPath -> ppDotPath.equals(dotPath))
115-
|| (dotPath.contains(".") && candidate.isPresent() &&
116-
projectingPropertyPaths.stream()
117-
.filter(pp -> pp.propertyPath.toDotPath().equals(candidate.get())).findFirst().get().isEntity);
116+
|| (dotPath.contains(".") && candidate.isPresent());
118117
}
119118

120119
@Override

0 commit comments

Comments
 (0)