DATAJDBC-219 - Polishing.

DeleteWithVersion doesn't require an entity anymore.
Added the `@author` and `@since` tags where they were missing.
Formatting.
Added documentation.

Original pull request: #166.
This commit is contained in:
Jens Schauder
2019-11-29 13:45:50 +01:00
parent f7a04dcc2b
commit ca2d2182d2
19 changed files with 190 additions and 157 deletions

View File

@@ -365,6 +365,21 @@ Note that whether an entity is new is part of the entity's state.
With auto-increment columns, this happens automatically, because the ID gets set by Spring Data with the value from the ID column.
If you are not using auto-increment columns, you can use a `BeforeSave` listener, which sets the ID of the entity (covered later in this document).
[[jdbc.entity-persistence.optimistic-locking]]
=== Optimistic Locking
Spring Data JDBC supports optimistic locking by means of a numeric attribute that is annotated with
https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/annotation/Version.html[`@Version`] on the aggregate root.
Whenever Spring Data JDBC saves an aggregate with such a version attribute two things happen:
The update statement for the aggregate root will contain a where clause checking that the version stored in the database is actually unchanged.
If this isn't the case an `OptimisticLockingFailureException` will be thrown.
Also the version attribute gets increased both in the entity and in the database so a concurrent action will notice the change and throw an `OptimisticLockingFailureException` if applicable as described above.
This process also applies to inserting new aggregates, where a `null` or `0` version indicates a new instance and the increased instance afterwards marks the instance as not new anymore, making this work rather nicely with cases where the id is generated during object construction for example when UUIDs are used.
During deletes the version check also applies but no version is increased.
[[jdbc.query-methods]]
== Query Methods

View File

@@ -3,6 +3,11 @@
This section covers the significant changes for each version.
[[new-features.2-0-0]]
== What's New in Spring Data JDBC 2.0
* Optimistic Locking support.
[[new-features.1-0-0]]
== What's New in Spring Data JDBC 1.0
@@ -13,3 +18,4 @@ This section covers the significant changes for each version.
* Event support.
* Auditing.
* `CustomConversions`.