Skip to content

Commit 685e54f

Browse files
GH-2214 - Improve documentation for @RelationshipProperties.
This closes #2214.
1 parent 21386b2 commit 685e54f

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/main/asciidoc/object-mapping/mapping.adoc

+4
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ You must define a property for the generated, internal ID so that SDN can determ
164164
can be safely overwritten without losing properties.
165165
If SDN does not find a field for storing the internal node id, it will fail during startup.
166166

167+
NOTE: The only supported generated ID field on classes annotated with `@RelationshipProperties` is `@GeneratedValue` with
168+
using the default ID generator `InternalIdGenerator` as shown above. Other generators will lead to a failure during
169+
startup..
170+
167171
.Defining relationship properties for an entity
168172
[source,java,indent=0]
169173
----

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

+33-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.List;
2929
import java.util.Map;
3030
import java.util.Set;
31+
import java.util.UUID;
3132

3233
import org.assertj.core.api.Assertions;
3334
import org.junit.jupiter.api.Nested;
@@ -75,7 +76,7 @@ class Neo4jMappingContextTest {
7576
class InvalidRelationshipProperties {
7677

7778
@Test // GH-2118
78-
void startupShouldFail() {
79+
void startupWithoutInternallyGeneratedIDShouldFail() {
7980

8081
Neo4jMappingContext schema = new Neo4jMappingContext();
8182
assertThatIllegalStateException().isThrownBy(() -> {
@@ -86,6 +87,18 @@ void startupShouldFail() {
8687
}).withMessage("The target class `org.springframework.data.neo4j.core.mapping.Neo4jMappingContextTest$InvalidRelationshipPropertyContainer` for the properties of the relationship `RELATIONSHIP_PROPERTY_CONTAINER` is missing a property for the generated, internal ID (`@Id @GeneratedValue Long id`) which is needed for safely updating properties.");
8788
}
8889

90+
@Test // GH-2214
91+
void startupWithWrongKindOfGeneratedIDShouldFail() {
92+
93+
Neo4jMappingContext schema = new Neo4jMappingContext();
94+
assertThatIllegalStateException().isThrownBy(() -> {
95+
schema.setInitialEntitySet(new HashSet<>(
96+
Arrays.asList(IrrelevantSourceContainer3.class, InvalidRelationshipPropertyContainer2.class,
97+
IrrelevantTargetContainer.class)));
98+
schema.initialize();
99+
}).withMessage("The target class `org.springframework.data.neo4j.core.mapping.Neo4jMappingContextTest$InvalidRelationshipPropertyContainer2` for the properties of the relationship `RELATIONSHIP_PROPERTY_CONTAINER` is missing a property for the generated, internal ID (`@Id @GeneratedValue Long id`) which is needed for safely updating properties.");
100+
}
101+
89102
@Test // GH-2118
90103
void noWarningShouldBeLogged(LogbackCapture logbackCapture) {
91104

@@ -578,6 +591,25 @@ static class InvalidRelationshipPropertyContainer {
578591
private IrrelevantTargetContainer irrelevantTargetContainer;
579592
}
580593

594+
@Node
595+
static class IrrelevantSourceContainer3 {
596+
@Id @GeneratedValue
597+
private Long id;
598+
599+
@Relationship(type = "RELATIONSHIP_PROPERTY_CONTAINER")
600+
InvalidRelationshipPropertyContainer2 relationshipPropertyContainer;
601+
}
602+
603+
@RelationshipProperties
604+
static class InvalidRelationshipPropertyContainer2 {
605+
606+
@Id @GeneratedValue(GeneratedValue.UUIDGenerator.class)
607+
private UUID id;
608+
609+
@TargetNode
610+
private IrrelevantTargetContainer irrelevantTargetContainer;
611+
}
612+
581613
@Node
582614
static class IrrelevantTargetContainer {
583615
@Id @GeneratedValue

0 commit comments

Comments
 (0)