From d3ee11732108459d5202416089a36932389d2bba Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Mon, 5 Jul 2021 12:27:30 +0200 Subject: [PATCH 1/3] 2401-constructor-detection - Prepare branch --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9001e043d4..fa0d706be1 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-commons - 2.6.0-SNAPSHOT + 2.6.0-2401-constructor-detection-SNAPSHOT Spring Data Core From 2cdd793871495283d5290edd55bdf462aeb049e2 Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Mon, 5 Jul 2021 12:28:59 +0200 Subject: [PATCH 2/3] Corrects the description of constructor detection. Closes #2401 --- src/main/asciidoc/object-mapping.adoc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/asciidoc/object-mapping.adoc b/src/main/asciidoc/object-mapping.adoc index ecd16c322b..323c46eed0 100644 --- a/src/main/asciidoc/object-mapping.adoc +++ b/src/main/asciidoc/object-mapping.adoc @@ -17,10 +17,10 @@ This means we need two fundamental steps: Spring Data automatically tries to detect a persistent entity's constructor to be used to materialize objects of that type. The resolution algorithm works as follows: -1. If there's a no-argument constructor, it will be used. +1. If there is a single constructor, it will be used. +2. If there are multiple constructors and exactly one is annotated with `@PersistenceConstructor`, it will be used. +3. If there's a no-argument constructor, it will be used. Other constructors will be ignored. -2. If there's a single constructor taking arguments, it will be used. -3. If there are multiple constructors taking arguments, the one to be used by Spring Data will have to be annotated with `@PersistenceConstructor`. 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.). This also requires either parameter names information available in the class file or an `@ConstructorProperties` annotation being present on the constructor. @@ -35,7 +35,7 @@ Please consult the section on store specific mappings for further details. To avoid the overhead of reflection, Spring Data object creation uses a factory class generated at runtime by default, which will call the domain classes constructor directly. I.e. for this example type: -[source, java] +[source,java] ---- class Person { Person(String firstname, String lastname) { … } From 0f14cb7e74cbfad41c957dbe4da6cb8d6955ec2f Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Wed, 7 Jul 2021 08:00:23 +0200 Subject: [PATCH 3/3] Applied review feedback by Jay Bryant to use simple present. --- src/main/asciidoc/object-mapping.adoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/asciidoc/object-mapping.adoc b/src/main/asciidoc/object-mapping.adoc index 323c46eed0..2e01cdfd48 100644 --- a/src/main/asciidoc/object-mapping.adoc +++ b/src/main/asciidoc/object-mapping.adoc @@ -17,9 +17,9 @@ This means we need two fundamental steps: Spring Data automatically tries to detect a persistent entity's constructor to be used to materialize objects of that type. The resolution algorithm works as follows: -1. If there is a single constructor, it will be used. -2. If there are multiple constructors and exactly one is annotated with `@PersistenceConstructor`, it will be used. -3. If there's a no-argument constructor, it will be used. +1. If there is a single constructor, it is used. +2. If there are multiple constructors and exactly one is annotated with `@PersistenceConstructor`, it is used. +3. If there's a no-argument constructor, it is used. Other constructors will be ignored. 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.).