Skip to content

Commit 7cb4da9

Browse files
committed
GH-2374 - Add documentation for Version.
Closes #2374
1 parent b39a39d commit 7cb4da9

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
@@ -170,6 +170,18 @@ That bean also needs to implement `IdGenerator`, but can make use of everything
170170

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

173+
[[mapping.annotations.version]]
174+
=== Optimistic locking: `@Version`
175+
176+
Spring Data Neo4j supports optimistic locking by using the `@Version` annotation on a `Long` typed field.
177+
This attribute will get incremented automatically during updates and must not be manually modified.
178+
179+
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.
180+
At this moment, the version field will get incremented, so it is `x+1`.
181+
The second operation will fail with a `OptimisticLockingFailureException` because it wants to modify the object with the version `x`
182+
that does not exist anymore in the database.
183+
In such cases the operation needs to get retried, beginning with a fresh fetch of the object with the current version from the database.
184+
173185
[[mapping.annotations.property]]
174186
=== Mapping properties: `@Property`
175187

0 commit comments

Comments
 (0)