From 72a2049a9d7541bdf94f77b00eb4179651266e27 Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Fri, 26 Mar 2021 09:26:50 +0100 Subject: [PATCH 1/3] version-doc - Prepare branch --- pom.xml | 2 +- spring-data-jdbc-distribution/pom.xml | 2 +- spring-data-jdbc/pom.xml | 4 ++-- spring-data-relational/pom.xml | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index b230bbb69e..0b7005c17c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-relational-parent - 2.2.0-SNAPSHOT + 2.2.0-version-doc-SNAPSHOT pom Spring Data Relational Parent diff --git a/spring-data-jdbc-distribution/pom.xml b/spring-data-jdbc-distribution/pom.xml index a922ef00a2..4c9e02e109 100644 --- a/spring-data-jdbc-distribution/pom.xml +++ b/spring-data-jdbc-distribution/pom.xml @@ -14,7 +14,7 @@ org.springframework.data spring-data-relational-parent - 2.2.0-SNAPSHOT + 2.2.0-version-doc-SNAPSHOT ../pom.xml diff --git a/spring-data-jdbc/pom.xml b/spring-data-jdbc/pom.xml index d00f04e6e3..9bea6d11be 100644 --- a/spring-data-jdbc/pom.xml +++ b/spring-data-jdbc/pom.xml @@ -6,7 +6,7 @@ 4.0.0 spring-data-jdbc - 2.2.0-SNAPSHOT + 2.2.0-version-doc-SNAPSHOT Spring Data JDBC Spring Data module for JDBC repositories. @@ -15,7 +15,7 @@ org.springframework.data spring-data-relational-parent - 2.2.0-SNAPSHOT + 2.2.0-version-doc-SNAPSHOT diff --git a/spring-data-relational/pom.xml b/spring-data-relational/pom.xml index 6b2507aabe..ea86c46c8f 100644 --- a/spring-data-relational/pom.xml +++ b/spring-data-relational/pom.xml @@ -6,7 +6,7 @@ 4.0.0 spring-data-relational - 2.2.0-SNAPSHOT + 2.2.0-version-doc-SNAPSHOT Spring Data Relational Spring Data Relational support @@ -14,7 +14,7 @@ org.springframework.data spring-data-relational-parent - 2.2.0-SNAPSHOT + 2.2.0-version-doc-SNAPSHOT From 6968c905f7023002152485d26a229ff501764bb0 Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Fri, 26 Mar 2021 10:02:30 +0100 Subject: [PATCH 2/3] Improve documentation of entity state detection. The use of a version property to determine the state of an entity wasn't properly documented so far. Related tickets https://github.com/spring-projects/spring-data-commons/issues/2338 --- src/main/asciidoc/jdbc.adoc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/asciidoc/jdbc.adoc b/src/main/asciidoc/jdbc.adoc index 7f8403ecde..1c65e4b745 100644 --- a/src/main/asciidoc/jdbc.adoc +++ b/src/main/asciidoc/jdbc.adoc @@ -437,8 +437,11 @@ The following table describes the strategies that Spring Data JDBC offers for de .Options for detection whether an entity is new in Spring Data JDBC [options = "autowidth"] |=============== -|Id-Property inspection (the default)|By default, Spring Data JDBC inspects the identifier property of the given entity. -If the identifier property is `null`, then the entity is assumed to be new. Otherwise, it is assumed to not be new. +|Id-Property inspection (the default)|By default, Spring Data JDBC inspects the version property of the given entity. +If the identifier property is `null` or `0` in case of primitve types, then the entity is assumed to be new. Otherwise, it is assumed to not be new. +|Version-Property inspection|If a property annotated with `@Version` is present and `null`, or in case of a version property of primitive type `0` the entity is considered new. +If the version property is present but has a different value, the entity is considered not new. +If no version property is present Spring Data JDBC falls back to inspection of the Id-Property. |Implementing `Persistable`|If an entity implements `Persistable`, Spring Data JDBC delegates the new detection to the `isNew(…)` method of the entity. See the link:$$https://docs.spring.io/spring-data/data-commons/docs/current/api/index.html?org/springframework/data/domain/Persistable.html$$[Javadoc] for details. |Implementing `EntityInformation`|You can customize the `EntityInformation` abstraction used in the `SimpleJdbcRepository` implementation by creating a subclass of `JdbcRepositoryFactory` and overriding the `getEntityInformation(…)` method. From f0d7073c55862de78162859e6d2c60742d7c85b8 Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Tue, 13 Apr 2021 14:35:33 +0200 Subject: [PATCH 3/3] Moved section about state detection to include in commons. This depends on https://github.com/spring-projects/spring-data-commons/pull/2352 --- src/main/asciidoc/jdbc.adoc | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/src/main/asciidoc/jdbc.adoc b/src/main/asciidoc/jdbc.adoc index 1c65e4b745..dcf9fd1689 100644 --- a/src/main/asciidoc/jdbc.adoc +++ b/src/main/asciidoc/jdbc.adoc @@ -430,24 +430,8 @@ Embedded entities containing a `Collection` or a `Map` will always be considered Such an entity will therefore never be `null` even when using @Embedded(onEmpty = USE_NULL). [[jdbc.entity-persistence.state-detection-strategies]] -=== Entity State Detection Strategies - -The following table describes the strategies that Spring Data JDBC offers for detecting whether an entity is new: - -.Options for detection whether an entity is new in Spring Data JDBC -[options = "autowidth"] -|=============== -|Id-Property inspection (the default)|By default, Spring Data JDBC inspects the version property of the given entity. -If the identifier property is `null` or `0` in case of primitve types, then the entity is assumed to be new. Otherwise, it is assumed to not be new. -|Version-Property inspection|If a property annotated with `@Version` is present and `null`, or in case of a version property of primitive type `0` the entity is considered new. -If the version property is present but has a different value, the entity is considered not new. -If no version property is present Spring Data JDBC falls back to inspection of the Id-Property. -|Implementing `Persistable`|If an entity implements `Persistable`, Spring Data JDBC delegates the new detection to the `isNew(…)` method of the entity. -See the link:$$https://docs.spring.io/spring-data/data-commons/docs/current/api/index.html?org/springframework/data/domain/Persistable.html$$[Javadoc] for details. -|Implementing `EntityInformation`|You can customize the `EntityInformation` abstraction used in the `SimpleJdbcRepository` implementation by creating a subclass of `JdbcRepositoryFactory` and overriding the `getEntityInformation(…)` method. -You then have to register the custom implementation of `JdbcRepositoryFactory` as a Spring bean. -Note that this should rarely be necessary. See the link:{javadoc-base}org/springframework/data/jdbc/repository/support/JdbcRepositoryFactory.html[Javadoc] for details. -|=============== +include::{spring-data-commons-docs}/entity-callbacks.adoc[leveloffset=+1] + [[jdbc.entity-persistence.id-generation]] === ID Generation @@ -892,7 +876,7 @@ The following table describes the available events: WARNING: Lifecycle events depend on an `ApplicationEventMulticaster`, which in case of the `SimpleApplicationEventMulticaster` can be configured with a `TaskExecutor`, and therefore gives no guarantees when an Event is processed. -include::{spring-data-commons-docs}/entity-callbacks.adoc[leveloffset=+1] +include::{spring-data-commons-docs}/is-new-state-detection.adoc[leveloffset=+2] [[jdbc.entity-callbacks]] === Store-specific EntityCallbacks