Commit 718a7ff
DATAMONGO-2150 - Fixed broken auditing for entities using optimistic locking.
The previous implementation of ReactiveMongoTemplate.doSaveVersioned(…) prematurely initialized the version property so that the entity wasn't considered new by the auditing subsystem. Even worse, for primitive version properties, the initialization kept the property at a value of 0, so that the just persisted entity was still considered new. This mean that via the repository route, inserts are triggered even for subsequent attempts to save an entity which caused duplicate key exceptions.
We now make sure we fire the BeforeConvertEvent before the version property is initialized or updated. Also, the initialization of the property now sets primitive properties to 1 initially.
Added integration tests for the auditing via ReactiveMongoTemplate and repositories.
Related ticket: DATAMONGO-2139.
Original Pull Request: #6271 parent f7106dc commit 718a7ff
File tree
3 files changed
+181
-39
lines changed- spring-data-mongodb/src
- main/java/org/springframework/data/mongodb/core
- test/java/org/springframework/data/mongodb
- config
- core
3 files changed
+181
-39
lines changedspring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java
Lines changed: 23 additions & 29 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1235 | 1235 | | |
1236 | 1236 | | |
1237 | 1237 | | |
1238 | | - | |
1239 | | - | |
1240 | 1238 | | |
1241 | 1239 | | |
1242 | | - | |
1243 | | - | |
1244 | | - | |
1245 | | - | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
1246 | 1243 | | |
| 1244 | + | |
| 1245 | + | |
1247 | 1246 | | |
1248 | 1247 | | |
1249 | | - | |
| 1248 | + | |
1250 | 1249 | | |
1251 | | - | |
| 1250 | + | |
1252 | 1251 | | |
1253 | 1252 | | |
1254 | | - | |
| 1253 | + | |
1255 | 1254 | | |
1256 | 1255 | | |
1257 | 1256 | | |
| |||
1389 | 1388 | | |
1390 | 1389 | | |
1391 | 1390 | | |
1392 | | - | |
| 1391 | + | |
1393 | 1392 | | |
1394 | | - | |
1395 | | - | |
1396 | | - | |
1397 | | - | |
1398 | | - | |
1399 | | - | |
| 1393 | + | |
| 1394 | + | |
1400 | 1395 | | |
1401 | 1396 | | |
1402 | | - | |
| 1397 | + | |
1403 | 1398 | | |
1404 | | - | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
1405 | 1402 | | |
1406 | 1403 | | |
1407 | 1404 | | |
1408 | | - | |
1409 | | - | |
1410 | | - | |
1411 | | - | |
1412 | | - | |
1413 | | - | |
1414 | | - | |
1415 | | - | |
| 1405 | + | |
| 1406 | + | |
1416 | 1407 | | |
1417 | | - | |
| 1408 | + | |
| 1409 | + | |
1418 | 1410 | | |
1419 | | - | |
| 1411 | + | |
1420 | 1412 | | |
1421 | 1413 | | |
1422 | 1414 | | |
| |||
1427 | 1419 | | |
1428 | 1420 | | |
1429 | 1421 | | |
1430 | | - | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
1431 | 1425 | | |
1432 | 1426 | | |
1433 | 1427 | | |
| |||
Lines changed: 154 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
Lines changed: 4 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
773 | 773 | | |
774 | 774 | | |
775 | 775 | | |
776 | | - | |
| 776 | + | |
777 | 777 | | |
778 | | - | |
779 | | - | |
780 | | - | |
781 | | - | |
| 778 | + | |
782 | 779 | | |
783 | 780 | | |
784 | 781 | | |
| |||
851 | 848 | | |
852 | 849 | | |
853 | 850 | | |
854 | | - | |
| 851 | + | |
855 | 852 | | |
856 | | - | |
857 | | - | |
858 | | - | |
859 | | - | |
| 853 | + | |
860 | 854 | | |
861 | 855 | | |
862 | 856 | | |
| |||
0 commit comments