Skip to content

Commit 78b374e

Browse files
GH-2118 - Polishing for 6.1.x.
This removes the logged warning and replaces it with an IllegalStateException. Removes the depreciations, updates the manual and additional tests that have been added in 6.1.x.
1 parent 1a9f7fa commit 78b374e

File tree

6 files changed

+25
-33
lines changed

6 files changed

+25
-33
lines changed

src/main/asciidoc/appendix/custom-queries.adoc

+3
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ public final class Person {
107107
@RelationshipProperties
108108
public final class Actor {
109109
110+
@Id @GeneratedValue
111+
private final Long id;
112+
110113
@TargetNode
111114
private final Person person;
112115

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ A relationship property class and its usage may look like this:
160160
include::../../../../src/test/java/org/springframework/data/neo4j/documentation/domain/Roles.java[tags=mapping.relationship.properties]
161161
----
162162

163-
You should define a property for the generated, internal ID so that SDN can determine during save which relationships
163+
You must define a property for the generated, internal ID so that SDN can determine during save which relationships
164164
can be safely overwritten without losing properties.
165-
A generated id property is optional in SDN 6.0.4 and upwards and will be required in SDN 6.1 for `@RelationshipProperties`.
165+
If SDN does not find a field for storing the internal node id, it will fail during startup.
166166

167167
.Defining relationship properties for an entity
168168
[source,java,indent=0]

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

+7-9
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,13 @@ private void verifyAssociationsWithProperties() {
266266
RelationshipDescription relationship = (RelationshipDescription) association;
267267
if (relationship.hasRelationshipProperties()) {
268268
NodeDescription<?> relationshipPropertiesEntity = relationship.getRelationshipPropertiesEntity();
269-
if (relationshipPropertiesEntity.getIdDescription() == null || !relationshipPropertiesEntity.getIdDescription().isInternallyGeneratedId()) {
270-
Supplier<CharSequence> messageSupplier = () -> String.format(
271-
"The target class `%s` for the properties of the relationship `%s` "
272-
+ "is missing a property for the generated, internal ID (`@Id @GeneratedValue Long id`). "
273-
+ "It is needed for safely updating properties and will be required from SDN 6.1 upwards.",
274-
relationshipPropertiesEntity.getUnderlyingClass().getName(),
275-
relationship.getType());
276-
log.warn(messageSupplier);
277-
}
269+
Supplier<String> messageSupplier = () -> String.format(
270+
"The target class `%s` for the properties of the relationship `%s` "
271+
+ "is missing a property for the generated, internal ID (`@Id @GeneratedValue Long id`) "
272+
+ "which is needed for safely updating properties.",
273+
relationshipPropertiesEntity.getUnderlyingClass().getName(),
274+
relationship.getType());
275+
Assert.state(relationshipPropertiesEntity.getIdDescription() != null && relationshipPropertiesEntity.getIdDescription().isInternallyGeneratedId(), messageSupplier);
278276
}
279277
}
280278
});

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

-17
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.springframework.data.mapping.PersistentProperty;
2424
import org.springframework.data.neo4j.core.schema.CompositeProperty;
2525
import org.springframework.data.neo4j.core.schema.DynamicLabels;
26-
import org.springframework.data.neo4j.core.schema.RelationshipProperties;
2726

2827
/**
2928
* A {@link org.springframework.data.mapping.PersistentProperty} interface with additional methods for metadata related
@@ -68,26 +67,10 @@ default boolean isDynamicLabels() {
6867
return this.isAnnotationPresent(DynamicLabels.class) && this.isCollectionLike();
6968
}
7069

71-
/**
72-
* @deprecated since 6.0.4, no replacement, not needed
73-
*/
74-
@Deprecated
75-
default boolean isRelationshipWithProperties() {
76-
return isAssociation() && isCollectionLike() && getActualType().isAnnotationPresent(RelationshipProperties.class);
77-
}
78-
7970
Function<Object, Value> getOptionalWritingConverter();
8071

8172
Function<Value, Object> getOptionalReadingConverter();
8273

83-
/**
84-
* @deprecated since 6.0.4, see #isEntityWithRelationshipProperties()
85-
*/
86-
@Deprecated
87-
default boolean isEntityInRelationshipWithProperties() {
88-
return isEntityWithRelationshipProperties();
89-
}
90-
9174
/**
9275
* @return True if this property targets an entity which is a container for relationship properties.
9376
*/

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,17 @@ class Neo4jMappingContextTest {
7373
@ExtendWith(LogbackCapturingExtension.class)
7474
@Nested
7575
class InvalidRelationshipProperties {
76+
7677
@Test // GH-2118
77-
void aWarningShouldBeLogged(LogbackCapture logbackCapture) {
78+
void startupShouldFail() {
7879

7980
Neo4jMappingContext schema = new Neo4jMappingContext();
80-
schema.setInitialEntitySet(new HashSet<>(Arrays.asList(IrrelevantSourceContainer.class, InvalidRelationshipPropertyContainer.class, IrrelevantTargetContainer.class)));
81-
schema.initialize();
82-
assertThat(logbackCapture.getFormattedMessages())
83-
.contains("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`). It is needed for safely updating properties and will be required from SDN 6.1 upwards.");
81+
assertThatIllegalStateException().isThrownBy(() -> {
82+
schema.setInitialEntitySet(new HashSet<>(
83+
Arrays.asList(IrrelevantSourceContainer.class, InvalidRelationshipPropertyContainer.class,
84+
IrrelevantTargetContainer.class)));
85+
schema.initialize();
86+
}).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.");
8487
}
8588

8689
@Test // GH-2118

src/test/java/org/springframework/data/neo4j/repository/query/Neo4jNestedMapEntityWriterTest.java

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import lombok.AllArgsConstructor;
2222
import lombok.RequiredArgsConstructor;
23+
import lombok.With;
2324

2425
import java.net.URI;
2526
import java.util.ArrayList;
@@ -592,8 +593,12 @@ static class A4 {
592593

593594
@RelationshipProperties
594595
@RequiredArgsConstructor
596+
@AllArgsConstructor
595597
static class P1 {
596598

599+
@Id @GeneratedValue @With
600+
private Long id;
601+
597602
private final String prop1;
598603

599604
private final String prop2;

0 commit comments

Comments
 (0)