Skip to content

Commit f47daef

Browse files
fix: Adapt to changes in Spring Data Commons 4.1
At the beginning of the investigation I thought the annotation of `SomeOtherClass` was the root case of the failure. While it caused the test failure—as it doesn't have an id property in fact—, it should not have been loaded at all: It is use as part of a transiently marked `List<>` property and Spring Data Commons 4.1 change a bit in that area and does add transient associations now (which I think it should not…). I fixed that with overriding the corresponding method and also removed the (superfluous) `@Node` annotation).
1 parent 71e87fc commit f47daef

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ private List<Class<?>> computeAggregateBoundaries() {
136136
/**
137137
* The primary label will get computed and returned by following rules:<br>
138138
* 1. If there is no {@link Node} annotation, use the class name.<br>
139-
* 2. If there is an annotation but it has no properties set, use the class name.<br>
139+
* 2. If there is an annotation, but it has no properties set, use the class name.<br>
140140
* 3. If only {@link Node#labels()} property is set, use the first one as the primary
141141
* label 4. If the {@link Node#primaryLabel()} property is set, use this as the
142142
* primary label
@@ -157,6 +157,14 @@ else if (StringUtils.hasText(nodeAnnotation.primaryLabel())) {
157157
}
158158
}
159159

160+
@Override
161+
public void addAssociation(Association<Neo4jPersistentProperty> association) {
162+
if (association.getInverse().isTransient()) {
163+
return;
164+
}
165+
super.addAssociation(association);
166+
}
167+
160168
/**
161169
* Checks if an entity is explicitly annotated.
162170
* @param entity the entity to check for annotation

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static String deriveRelationshipType(String name) {
141141
}
142142
codePoint = Character.toUpperCase(codePoint);
143143
}
144-
else if (sb.length() > 0) {
144+
else if (!sb.isEmpty()) {
145145
sb.append("_");
146146
}
147147
sb.append(Character.toChars(codePoint));

src/test/java/org/springframework/data/neo4j/core/mapping/Neo4jMappingContextTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,15 @@ void complexPropertyWithoutConverterShouldBeConsideredAsAssociation() {
259259
void shouldHonourTransientAnnotation() {
260260

261261
Neo4jMappingContext schema = new Neo4jMappingContext();
262-
Neo4jPersistentEntity<?> userNodeEntity = schema.getPersistentEntity(UserNode.class);
262+
Neo4jPersistentEntity<?> userNodeEntity = schema.getRequiredPersistentEntity(UserNode.class);
263263

264+
assertThat(userNodeEntity.getTransientProperty("someOtherTransientThings")).isNotNull();
265+
assertThat(userNodeEntity.getTransientProperty("anAnnotatedTransientProperty")).isNotNull();
264266
assertThat(userNodeEntity.getPersistentProperty("anAnnotatedTransientProperty")).isNull();
265267

266268
List<String> associations = new ArrayList<>();
267-
userNodeEntity.doWithAssociations((Association<Neo4jPersistentProperty> a) -> {
268-
associations.add(a.getInverse().getFieldName());
269-
});
269+
userNodeEntity.doWithAssociations(
270+
(Association<Neo4jPersistentProperty> a) -> associations.add(a.getInverse().getFieldName()));
270271

271272
assertThat(associations).containsOnly("bikes", "theSuperBike");
272273
}
@@ -806,7 +807,6 @@ static class UserNode {
806807

807808
}
808809

809-
@Node
810810
static class SomeOtherClass {
811811

812812
}

0 commit comments

Comments
 (0)