You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#402 - Exclude id property using initial value when inserting objects.
We now exclude Id properties from being used in the INSERT field list if the Id value is zero and of a primitive type or if the value is null using a numeric wrapper type.
Copy file name to clipboardExpand all lines: src/main/asciidoc/reference/r2dbc-repositories.adoc
+7-3
Original file line number
Diff line number
Diff line change
@@ -332,6 +332,9 @@ The ID of an entity must be annotated with Spring Data's https://docs.spring.io/
332
332
333
333
When your database has an auto-increment column for the ID column, the generated value gets set in the entity after inserting it into the database.
334
334
335
+
Spring Data R2DBC does not attempt to insert values of identifier columns when the entity is new and the identifier value defaults to its initial value.
336
+
That is `0` for primitive types and `null` if the identifier property uses a numeric wrapper type such as `Long`.
337
+
335
338
One important constraint is that, after saving an entity, the entity must not be new anymore.
336
339
Note that whether an entity is new is part of the entity's state.
337
340
With auto-increment columns, this happens automatically, because the ID gets set by Spring Data with the value from the ID column.
@@ -340,7 +343,8 @@ With auto-increment columns, this happens automatically, because the ID gets set
340
343
=== Optimistic Locking
341
344
342
345
The `@Version` annotation provides syntax similar to that of JPA in the context of R2DBC and makes sure updates are only applied to documents with a matching version.
343
-
Therefore, the actual value of the version property is added to the update query in such a way that the update does not have any effect if another operation altered the document in the meantime. In that case, an `OptimisticLockingFailureException` is thrown.
346
+
Therefore, the actual value of the version property is added to the update query in such a way that the update does not have any effect if another operation altered the document in the meantime.
347
+
In that case, an `OptimisticLockingFailureException` is thrown.
<1> Initially insert row. `version` is set to `0`.
372
376
<2> Load the just inserted row. `version` is still `0`.
373
-
<3> Update the row with `version = 0`.Set the `lastname` and bump `version` to `1`.
374
-
<4> Try to update the previously loaded document that still has `version = 0`.The operation fails with an `OptimisticLockingFailureException`, as the current `version` is `1`.
377
+
<3> Update the row with `version = 0`.Set the `lastname` and bump `version` to `1`.
378
+
<4> Try to update the previously loaded document that still has `version = 0`.The operation fails with an `OptimisticLockingFailureException`, as the current `version` is `1`.
0 commit comments