DATAMONGO-2195 - Consider version when removing an entity.

We now consider a potential @Version when removing an entity.

MongoOperations#remove(Object) and MongoOperations#remove(Object, String) include the version of the object to remove if the entity is versioned. Opposed to save(Object), remove(Object) does not throw OptimisticLockingFailureException if a versioned entity could not be removed. This behavior is subject to be changed in a future release. Throwing OptimisticLockingFailureException on failed delete on Template API level was not introduced to not break existing application code.

MongoRepository now also considers the entities version, following the very same logic as MongoOperations.
To remove an entity without version check use MongoOperations#remove(Query,…) or MongoRepository#deleteById(…).

Original pull request: #641.
This commit is contained in:
Christoph Strobl
2019-02-04 12:48:02 +01:00
committed by Mark Paluch
parent e8a3b6935e
commit 4ecf20ce4c
13 changed files with 584 additions and 22 deletions

View File

@@ -1080,6 +1080,11 @@ template.save(tmp); // throws OptimisticLockingFailureException
IMPORTANT: Optimistic Locking requires to set the `WriteConcern` to `ACKNOWLEDGED`. Otherwise `OptimisticLockingFailureException` can be silently swallowed.
NOTE: As of Version 2.2 `MongoOperations` also includes the `@Version` property when removing an entity from the database, raising an
`OptimisticLockingFailureException` if a document with matching `_id` but a `version` mismatch shall be deleted. In cases
where no Document with matching `_id` can be found the operation passes without error.
To remove a `Document` without version check use `MongoOperations#remove(Query,...)` instead of `MongoOperations#remove(Object)`.
[[mongo.query]]
== Querying Documents