Skip to content

Commit 8935931

Browse files
GH-2491 - Replace usage of deprecated PersistenceConstructor with PersistentCreator.
Closes #2491.
1 parent ff206fc commit 8935931

14 files changed

+30
-30
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ See <<conversions>> for more information on that.
4646
* `@CreatedDate`: Applied at the field level to indicate the creation date of a node.
4747
* `@LastModifiedBy`: Applied at the field level to indicate the author of the last change to a node.
4848
* `@LastModifiedDate`: Applied at the field level to indicate the last modification date of a node.
49-
* `@PersistenceConstructor`: Applied at one constructor to mark it as the preferred constructor when reading entities.
49+
* `@PersistenceCreator`: Applied at one constructor to mark it as the preferred constructor when reading entities.
5050
* `@Persistent`: Applied at the class level to indicate this class is a candidate for mapping to the database.
5151
* `@Version`: Applied at field level it is used for optimistic locking and checked for modification on save operations.
5252
The initial value is zero which is bumped automatically on every update.

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The resolution algorithm works as follows:
1818
1. If there is a no-argument constructor, it will be used.
1919
Other constructors will be ignored.
2020
2. If there is a single constructor taking arguments, it will be used.
21-
3. If there are multiple constructors taking arguments, the one to be used by Spring Data will have to be annotated with `@PersistenceConstructor`.
21+
3. If there are multiple constructors taking arguments, the one to be used by Spring Data will have to be annotated with `@PersistenceCreator`.
2222

2323
The value resolution assumes constructor argument names to match the property names of the entity, i.e. the resolution will be performed as if the property was to be populated, including all customizations in mapping (different datastore column or field name etc.).
2424
This also requires either parameter names information available in the class file or an `@ConstructorProperties` annotation being present on the constructor.
@@ -201,7 +201,7 @@ Even if the intent is that the calculation should be preferred, it's important t
201201
<.> The `comment` property is mutable is populated by setting its field directly.
202202
<.> The `remarks` properties are mutable and populated by setting the `comment` field directly or by invoking the setter method for
203203
<.> The class exposes a factory method and a constructor for object creation.
204-
The core idea here is to use factory methods instead of additional constructors to avoid the need for constructor disambiguation through `@PersistenceConstructor`.
204+
The core idea here is to use factory methods instead of additional constructors to avoid the need for constructor disambiguation through `@PersistenceCreator`.
205205
Instead, defaulting of properties is handled within the factory method.
206206

207207
[[mapping.fundamentals.recommendations]]
@@ -214,7 +214,7 @@ If you need those, prefer to make them package protected so that they can only b
214214
Constructor-only materialization is up to 30% faster than properties population.
215215
* _Provide an all-args constructor_ --
216216
Even if you cannot or don't want to model your entities as immutable values, there's still value in providing a constructor that takes all properties of the entity as arguments, including the mutable ones, as this allows the object mapping to skip the property population for optimal performance.
217-
* _Use factory methods instead of overloaded constructors to avoid ``@PersistenceConstructor``_ --
217+
* _Use factory methods instead of overloaded constructors to avoid ``@PersistenceCreator``_ --
218218
With an all-argument constructor needed for optimal performance, we usually want to expose more application use case specific constructors that omit things like auto-generated identifiers etc.
219219
It's an established pattern to rather use static factory methods to expose these variants of the all-args constructor.
220220
* _Make sure you adhere to the constraints that allow the generated instantiator and property accessor classes to be used_
@@ -251,14 +251,14 @@ data class Person(val id: String, val name: String)
251251
====
252252

253253
The class above compiles to a typical class with an explicit constructor.
254-
We can customize this class by adding another constructor and annotate it with `@PersistenceConstructor` to indicate a constructor preference:
254+
We can customize this class by adding another constructor and annotate it with `@PersistenceCreator` to indicate a constructor preference:
255255

256256
====
257257
[source,java]
258258
----
259259
data class Person(var id: String, val name: String) {
260260
261-
@PersistenceConstructor
261+
@PersistenceCreator
262262
constructor(id: String) : this(id, "unknown")
263263
}
264264
----

src/test/java/org/springframework/data/neo4j/integration/movies/shared/Person.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.util.ArrayList;
1919
import java.util.List;
2020

21-
import org.springframework.data.annotation.PersistenceConstructor;
21+
import org.springframework.data.annotation.PersistenceCreator;
2222
import org.springframework.data.neo4j.core.schema.GeneratedValue;
2323
import org.springframework.data.neo4j.core.schema.Id;
2424
import org.springframework.data.neo4j.core.schema.Node;
@@ -44,7 +44,7 @@ public final class Person {
4444
@Relationship("ACTED_IN")
4545
private List<Movie> actedIn = new ArrayList<>();
4646

47-
@PersistenceConstructor
47+
@PersistenceCreator
4848
private Person(Long id, String name, Integer born) {
4949
this.id = id;
5050
this.born = born;

src/test/java/org/springframework/data/neo4j/integration/shared/common/ImmutableAuditableThing.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.springframework.data.annotation.Id;
2727
import org.springframework.data.annotation.LastModifiedBy;
2828
import org.springframework.data.annotation.LastModifiedDate;
29-
import org.springframework.data.annotation.PersistenceConstructor;
29+
import org.springframework.data.annotation.PersistenceCreator;
3030
import org.springframework.data.annotation.Persistent;
3131
import org.springframework.data.neo4j.core.schema.GeneratedValue;
3232

@@ -35,7 +35,7 @@
3535
*/
3636
@Value
3737
@With
38-
@AllArgsConstructor(onConstructor = @__(@PersistenceConstructor))
38+
@AllArgsConstructor(onConstructor = @__(@PersistenceCreator))
3939
@Persistent
4040
public class ImmutableAuditableThing implements AuditableThing {
4141

src/test/java/org/springframework/data/neo4j/integration/shared/common/ImmutableAuditableThingWithGeneratedId.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.springframework.data.annotation.Id;
2727
import org.springframework.data.annotation.LastModifiedBy;
2828
import org.springframework.data.annotation.LastModifiedDate;
29-
import org.springframework.data.annotation.PersistenceConstructor;
29+
import org.springframework.data.annotation.PersistenceCreator;
3030
import org.springframework.data.annotation.Persistent;
3131
import org.springframework.data.neo4j.core.schema.GeneratedValue;
3232
import org.springframework.data.neo4j.core.support.UUIDStringGenerator;
@@ -36,7 +36,7 @@
3636
*/
3737
@Value
3838
@With
39-
@AllArgsConstructor(onConstructor = @__(@PersistenceConstructor))
39+
@AllArgsConstructor(onConstructor = @__(@PersistenceCreator))
4040
@Persistent
4141
public class ImmutableAuditableThingWithGeneratedId implements AuditableThing {
4242

src/test/java/org/springframework/data/neo4j/integration/shared/common/ImmutablePersonWithAssignedId.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package org.springframework.data.neo4j.integration.shared.common;
1717

18-
import org.springframework.data.annotation.PersistenceConstructor;
18+
import org.springframework.data.annotation.PersistenceCreator;
1919
import org.springframework.data.neo4j.core.schema.Id;
2020
import org.springframework.data.neo4j.core.schema.Node;
2121
import org.springframework.data.neo4j.core.schema.Relationship;
@@ -57,7 +57,7 @@ public class ImmutablePersonWithAssignedId {
5757
public final Map<String, ImmutablePersonWithAssignedIdRelationshipProperties> relationshipPropertiesDynamic;
5858
public final Map<String, List<ImmutableSecondPersonWithAssignedIdRelationshipProperties>> relationshipPropertiesDynamicCollection;
5959

60-
@PersistenceConstructor
60+
@PersistenceCreator
6161
public ImmutablePersonWithAssignedId(
6262
Long id,
6363
List<ImmutablePersonWithAssignedId> wasOnboardedBy,

src/test/java/org/springframework/data/neo4j/integration/shared/common/ImmutablePersonWithExternallyGeneratedId.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package org.springframework.data.neo4j.integration.shared.common;
1717

18-
import org.springframework.data.annotation.PersistenceConstructor;
18+
import org.springframework.data.annotation.PersistenceCreator;
1919
import org.springframework.data.neo4j.core.schema.GeneratedValue;
2020
import org.springframework.data.neo4j.core.schema.Id;
2121
import org.springframework.data.neo4j.core.schema.Node;
@@ -57,7 +57,7 @@ public class ImmutablePersonWithExternallyGeneratedId {
5757
public final Map<String, ImmutablePersonWithExternallyGeneratedIdRelationshipProperties> relationshipPropertiesDynamic;
5858
public final Map<String, List<ImmutableSecondPersonWithExternallyGeneratedIdRelationshipProperties>> relationshipPropertiesDynamicCollection;
5959

60-
@PersistenceConstructor
60+
@PersistenceCreator
6161
public ImmutablePersonWithExternallyGeneratedId(
6262
UUID id,
6363
List<ImmutablePersonWithExternallyGeneratedId> wasOnboardedBy,

src/test/java/org/springframework/data/neo4j/integration/shared/common/ImmutablePersonWithGeneratedId.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package org.springframework.data.neo4j.integration.shared.common;
1717

18-
import org.springframework.data.annotation.PersistenceConstructor;
18+
import org.springframework.data.annotation.PersistenceCreator;
1919
import org.springframework.data.neo4j.core.schema.GeneratedValue;
2020
import org.springframework.data.neo4j.core.schema.Id;
2121
import org.springframework.data.neo4j.core.schema.Node;
@@ -55,7 +55,7 @@ public class ImmutablePersonWithGeneratedId {
5555
public final Map<String, ImmutablePersonWithGeneratedIdRelationshipProperties> relationshipPropertiesDynamic;
5656
public final Map<String, List<ImmutableSecondPersonWithGeneratedIdRelationshipProperties>> relationshipPropertiesDynamicCollection;
5757

58-
@PersistenceConstructor
58+
@PersistenceCreator
5959
public ImmutablePersonWithGeneratedId(
6060
Long id,
6161
List<ImmutablePersonWithGeneratedId> wasOnboardedBy,

src/test/java/org/springframework/data/neo4j/integration/shared/common/ImmutablePet.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package org.springframework.data.neo4j.integration.shared.common;
1717

18-
import org.springframework.data.annotation.PersistenceConstructor;
18+
import org.springframework.data.annotation.PersistenceCreator;
1919
import org.springframework.data.neo4j.core.schema.GeneratedValue;
2020
import org.springframework.data.neo4j.core.schema.Id;
2121
import org.springframework.data.neo4j.core.schema.Node;
@@ -38,7 +38,7 @@ public class ImmutablePet {
3838
@Relationship("Has")
3939
public final Set<ImmutablePet> friends;
4040

41-
@PersistenceConstructor
41+
@PersistenceCreator
4242
public ImmutablePet(Long id, String name) {
4343
this.id = id;
4444
this.name = name;

src/test/java/org/springframework/data/neo4j/integration/shared/common/ImmutableSecondPersonWithAssignedId.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package org.springframework.data.neo4j.integration.shared.common;
1717

18-
import org.springframework.data.annotation.PersistenceConstructor;
18+
import org.springframework.data.annotation.PersistenceCreator;
1919
import org.springframework.data.neo4j.core.schema.Id;
2020
import org.springframework.data.neo4j.core.schema.Node;
2121
import org.springframework.data.neo4j.core.schema.Relationship;
@@ -55,7 +55,7 @@ public class ImmutableSecondPersonWithAssignedId {
5555
public final Map<String, ImmutablePersonWithAssignedIdRelationshipProperties> relationshipPropertiesDynamic;
5656
public final Map<String, List<ImmutableSecondPersonWithAssignedIdRelationshipProperties>> relationshipPropertiesDynamicCollection;
5757

58-
@PersistenceConstructor
58+
@PersistenceCreator
5959
public ImmutableSecondPersonWithAssignedId(
6060
Long id,
6161
List<ImmutableSecondPersonWithAssignedId> wasOnboardedBy,

src/test/java/org/springframework/data/neo4j/integration/shared/common/ImmutableSecondPersonWithExternallyGeneratedId.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package org.springframework.data.neo4j.integration.shared.common;
1717

18-
import org.springframework.data.annotation.PersistenceConstructor;
18+
import org.springframework.data.annotation.PersistenceCreator;
1919
import org.springframework.data.neo4j.core.schema.GeneratedValue;
2020
import org.springframework.data.neo4j.core.schema.Id;
2121
import org.springframework.data.neo4j.core.schema.Node;
@@ -57,7 +57,7 @@ public class ImmutableSecondPersonWithExternallyGeneratedId {
5757
public final Map<String, ImmutablePersonWithExternallyGeneratedIdRelationshipProperties> relationshipPropertiesDynamic;
5858
public final Map<String, List<ImmutableSecondPersonWithExternallyGeneratedIdRelationshipProperties>> relationshipPropertiesDynamicCollection;
5959

60-
@PersistenceConstructor
60+
@PersistenceCreator
6161
public ImmutableSecondPersonWithExternallyGeneratedId(
6262
UUID id,
6363
List<ImmutableSecondPersonWithExternallyGeneratedId> wasOnboardedBy,

src/test/java/org/springframework/data/neo4j/integration/shared/common/ImmutableSecondPersonWithGeneratedId.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package org.springframework.data.neo4j.integration.shared.common;
1717

18-
import org.springframework.data.annotation.PersistenceConstructor;
18+
import org.springframework.data.annotation.PersistenceCreator;
1919
import org.springframework.data.neo4j.core.schema.GeneratedValue;
2020
import org.springframework.data.neo4j.core.schema.Id;
2121
import org.springframework.data.neo4j.core.schema.Node;
@@ -54,7 +54,7 @@ public class ImmutableSecondPersonWithGeneratedId {
5454
public final Map<String, ImmutablePersonWithGeneratedIdRelationshipProperties> relationshipPropertiesDynamic;
5555
public final Map<String, List<ImmutableSecondPersonWithGeneratedIdRelationshipProperties>> relationshipPropertiesDynamicCollection;
5656

57-
@PersistenceConstructor
57+
@PersistenceCreator
5858
public ImmutableSecondPersonWithGeneratedId(
5959
Long id,
6060
List<ImmutableSecondPersonWithGeneratedId> wasOnboardedBy,

src/test/java/org/springframework/data/neo4j/integration/shared/common/PersonWithRelationshipWithProperties.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.util.List;
1919
import java.util.Set;
2020

21-
import org.springframework.data.annotation.PersistenceConstructor;
21+
import org.springframework.data.annotation.PersistenceCreator;
2222
import org.springframework.data.neo4j.core.schema.GeneratedValue;
2323
import org.springframework.data.neo4j.core.schema.Id;
2424
import org.springframework.data.neo4j.core.schema.Node;
@@ -44,7 +44,7 @@ public class PersonWithRelationshipWithProperties {
4444

4545
@Relationship("OWNS") private List<ClubRelationship> clubs;
4646

47-
@PersistenceConstructor
47+
@PersistenceCreator
4848
public PersonWithRelationshipWithProperties(Long id, String name, List<LikesHobbyRelationship> hobbies, WorksInClubRelationship club) {
4949
this.id = id;
5050
this.name = name;

src/test/java/org/springframework/data/neo4j/integration/shared/common/Pet.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.util.List;
2323
import java.util.Set;
2424

25-
import org.springframework.data.annotation.PersistenceConstructor;
25+
import org.springframework.data.annotation.PersistenceCreator;
2626
import org.springframework.data.neo4j.core.schema.GeneratedValue;
2727
import org.springframework.data.neo4j.core.schema.Id;
2828
import org.springframework.data.neo4j.core.schema.Node;
@@ -31,7 +31,7 @@
3131
/**
3232
* @author Gerrit Meier
3333
*/
34-
@RequiredArgsConstructor(onConstructor = @__(@PersistenceConstructor))
34+
@RequiredArgsConstructor(onConstructor = @__(@PersistenceCreator))
3535
@Getter
3636
@EqualsAndHashCode(of = { "id", "name" })
3737
@Node

0 commit comments

Comments
 (0)