Skip to content

Commit 50e3d66

Browse files
committed
GH-2374 - Add documentation for Version.
1 parent 7dc0675 commit 50e3d66

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,18 @@ That bean also needs to implement `IdGenerator`, but can make use of everything
174174

175175
NOTE: Don't skip the important notes about ID handling in <<mapping.id-handling>>
176176

177+
[[mapping.annotations.version]]
178+
=== Optimistic locking: `@Version`
179+
180+
Spring Data Neo4j supports optimistic locking by using the `@Version` annotation on a `Long` typed field.
181+
This attribute will get incremented automatically during updates and must not be manually modified.
182+
183+
If, e.g., two transactions in different threads want to modify the same object with version `x`, the first operation will get successfully persisted to the database.
184+
At this moment, the version field will get incremented, so it is `x+1`.
185+
The second operation will fail with a `OptimisticLockingFailureException` because it wants to modify the object with the version `x`
186+
that does not exist anymore in the database.
187+
In such cases the operation needs to get retried, beginning with a fresh fetch of the object with the current version from the database.
188+
177189
[[mapping.annotations.property]]
178190
=== Mapping properties: `@Property`
179191

0 commit comments

Comments
 (0)