Я просто выполняю простые транзакции, такие как:
- findByVariable (строковая переменная);
- манипулирует данными, затем
- save (data);
но я получил Исключение, подобное этому
org.springframework.dao.OptimisticLockingFailureException: Optimistic lock exception on saving entity: Document{{dataKey=A, lastValue=XXX, version=1, createdDate=Mon Apr 13 21:53:25 WIB 2020, updatedDate=Mon Apr 13 22:34:28 WIB 2020, _class=SomeData}} to collection some_data
at org.springframework.data.mongodb.core.ReactiveMongoTemplate.lambda$doUpdate$65(ReactiveMongoTemplate.java:1819)
at reactor.core.publisher.FluxPeek$PeekSubscriber.onNext(FluxPeek.java:177)
at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onNext(FluxOnErrorResume.java:73)
at reactor.core.publisher.MonoFlatMapMany$FlatMapManyInner.onNext(MonoFlatMapMany.java:242)
at com.mongodb.reactivestreams.client.internal.SingleResultObservableToPublisher$1.onNext(SingleResultObservableToPublisher.java:42)
at com.mongodb.reactivestreams.client.internal.ObservableToPublisher$1.onNext(ObservableToPublisher.java:66)
at com.mongodb.async.client.AbstractSubscription.onNext(AbstractSubscription.java:142)
at com.mongodb.async.client.AbstractSubscription.processResultsQueue(AbstractSubscription.java:217)
at com.mongodb.async.client.AbstractSubscription.tryProcessResultsQueue(AbstractSubscription.java:172)
at com.mongodb.async.client.SingleResultCallbackSubscription$1.onResult(SingleResultCallbackSubscription.java:48)
at com.mongodb.async.client.MongoCollectionImpl$4.onResult(MongoCollectionImpl.java:647)
at com.mongodb.async.client.MongoCollectionImpl$4.onResult(MongoCollectionImpl.java:641)
at com.mongodb.async.client.MongoCollectionImpl$10.onResult(MongoCollectionImpl.java:1138)
at com.mongodb.async.client.MongoCollectionImpl$10.onResult(MongoCollectionImpl.java:1122)
at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
at com.mongodb.async.client.OperationExecutorImpl$2$1$1.onResult(OperationExecutorImpl.java:140)
at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
at com.mongodb.operation.OperationHelper$ConnectionReleasingWrappedCallback.onResult(OperationHelper.java:432)
at com.mongodb.operation.MixedBulkWriteOperation.addBatchResult(MixedBulkWriteOperation.java:527)
at com.mongodb.operation.MixedBulkWriteOperation.access$1600(MixedBulkWriteOperation.java:72)
at com.mongodb.operation.MixedBulkWriteOperation$6.onResult(MixedBulkWriteOperation.java:507)
at com.mongodb.operation.MixedBulkWriteOperation$6.onResult(MixedBulkWriteOperation.java:479)
at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
at com.mongodb.internal.connection.DefaultServer$DefaultServerProtocolExecutor$2.onResult(DefaultServer.java:245)
at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
at com.mongodb.internal.connection.CommandProtocolImpl$1.onResult(CommandProtocolImpl.java:85)
at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection$1.onResult(DefaultConnectionPool.java:467)
at com.mongodb.internal.connection.UsageTrackingInternalConnection$2.onResult(UsageTrackingInternalConnection.java:111)
at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
at com.mongodb.internal.connection.InternalStreamConnection$2$1.onResult(InternalStreamConnection.java:399)
at com.mongodb.internal.connection.InternalStreamConnection$2$1.onResult(InternalStreamConnection.java:376)
at com.mongodb.internal.connection.InternalStreamConnection$MessageHeaderCallback$MessageCallback.onResult(InternalStreamConnection.java:677)
at com.mongodb.internal.connection.InternalStreamConnection$MessageHeaderCallback$MessageCallback.onResult(InternalStreamConnection.java:644)
at com.mongodb.internal.connection.InternalStreamConnection$5.completed(InternalStreamConnection.java:514)
at com.mongodb.internal.connection.InternalStreamConnection$5.completed(InternalStreamConnection.java:511)
at com.mongodb.connection.netty.NettyStream.readAsync(NettyStream.java:233)
at com.mongodb.internal.connection.InternalStreamConnection.readAsync(InternalStreamConnection.java:511)
at com.mongodb.internal.connection.InternalStreamConnection.access$1000(InternalStreamConnection.java:76)
at com.mongodb.internal.connection.InternalStreamConnection$MessageHeaderCallback.onResult(InternalStreamConnection.java:634)
at com.mongodb.internal.connection.InternalStreamConnection$MessageHeaderCallback.onResult(InternalStreamConnection.java:619)
at com.mongodb.internal.connection.InternalStreamConnection$5.completed(InternalStreamConnection.java:514)
at com.mongodb.internal.connection.InternalStreamConnection$5.completed(InternalStreamConnection.java:511)
at com.mongodb.connection.netty.NettyStream.readAsync(NettyStream.java:233)
at com.mongodb.connection.netty.NettyStream.handleReadResponse(NettyStream.java:263)
at com.mongodb.connection.netty.NettyStream.access$800(NettyStream.java:69)
at com.mongodb.connection.netty.NettyStream$InboundBufferHandler.channelRead0(NettyStream.java:322)
at com.mongodb.connection.netty.NettyStream$InboundBufferHandler.channelRead0(NettyStream.java:319)
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:377)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:355)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:377)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
У меня @Version
уже на моем объекте, и когда я отлаживал, я увидел, что версия больше, чем существующее значение в базе данных. в базе данных version
равен 0
, и именно тогда, когда я пытаюсь save(data)
, version
увеличился до 1
, что является правильным.
Я уже прочитал весенние документы о Mongodb Optimisti c Блокировка и я думаю, что я не сделал ничего плохого: ')
Пожалуйста, посмотрите мою сущность ниже
@Data
@EqualsAndHashCode(callSuper = true)
@SuperBuilder
@NoArgsConstructor
@Document(collection = CollectionName.SOME_DATA)
public class SomeData implement Serializable {
private static final long serialVersionUID = 1L;
@Id
@Field(value = "_id")
private String id;
@Version
@Field(value = "version")
private Long version;
@CreatedDate
@Field(value = "createdDate")
private Date createdDate;
@LastModifiedDate
@Field(value = "updatedDate")
private Date updatedDate;
@Indexed
@Field(value = "dataKey")
private String dataKey;
@Indexed
@Field(value = "lastValue")
private String lastValue;
}