Hello,
Spring Boot 2.0.0.M4
mongodb-driver-reactivestreams 1.6.0
I'm facing a bug that appear when I save an entity with @DbRef
Look this test :
@Test
public void testMongoDbRef() {
AccountEntity account = AccountBuilder.createDefaultAccountEntity();
accountRepository.save(account).subscribe(accountEntity -> System.out.println(account.getId()));
CustomerEntity customer = CustomerBuilder.createCustomerEntity();
customer.setAccount(account);
customerRepository.save(customer).subscribe(customerEntity -> System.out.println(customerEntity.getId()));
}
@DBRef
@Field(CustomerDef.ACCOUNT)
private AccountEntity account;
and the result is :
2017-09-19 13:08:09,042 WARN main client.warn - Callback onResult call produced an error
reactor.core.Exceptions$ErrorCallbackNotImplemented: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class com.mongodb.DBRef.
Caused by: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class com.mongodb.DBRef.
at org.bson.codecs.configuration.CodecCache.getOrThrow(CodecCache.java:46)
at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:63)
at org.bson.codecs.configuration.ChildCodecRegistry.get(ChildCodecRegistry.java:51)
at org.bson.codecs.DocumentCodec.writeValue(DocumentCodec.java:174)
at org.bson.codecs.DocumentCodec.writeMap(DocumentCodec.java:189)
at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:131)
at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:45)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:63)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:29)
at com.mongodb.connection.InsertCommandMessage.writeTheWrites(InsertCommandMessage.java:101)
at com.mongodb.connection.InsertCommandMessage.writeTheWrites(InsertCommandMessage.java:43)
at com.mongodb.connection.BaseWriteCommandMessage.encodeMessageBodyWithMetadata(BaseWriteCommandMessage.java:129)
at com.mongodb.connection.RequestMessage.encodeWithMetadata(RequestMessage.java:160)
at com.mongodb.connection.WriteCommandProtocol.executeBatchesAsync(WriteCommandProtocol.java:150)
at com.mongodb.connection.WriteCommandProtocol.executeAsync(WriteCommandProtocol.java:137)
at com.mongodb.connection.InsertCommandProtocol.executeAsync(InsertCommandProtocol.java:80)
at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.executeAsync(DefaultServer.java:179)
at com.mongodb.connection.DefaultServerConnection.executeProtocolAsync(DefaultServerConnection.java:295)
at com.mongodb.connection.DefaultServerConnection.insertCommandAsync(DefaultServerConnection.java:131)
at com.mongodb.operation.MixedBulkWriteOperation$Run$5.executeWriteCommandProtocolAsync(MixedBulkWriteOperation.java:533)
at com.mongodb.operation.MixedBulkWriteOperation$Run$AsyncRunExecutor.executeAsync(MixedBulkWriteOperation.java:703)
at com.mongodb.operation.MixedBulkWriteOperation$Run.executeAsync(MixedBulkWriteOperation.java:425)
at com.mongodb.operation.MixedBulkWriteOperation.executeRunsAsync(MixedBulkWriteOperation.java:230)
at com.mongodb.operation.MixedBulkWriteOperation.access$600(MixedBulkWriteOperation.java:74)
at com.mongodb.operation.MixedBulkWriteOperation$2$1.call(MixedBulkWriteOperation.java:212)
at com.mongodb.operation.OperationHelper$3.call(OperationHelper.java:185)
at com.mongodb.operation.OperationHelper.validateCollationAndWriteConcern(OperationHelper.java:140)
at com.mongodb.operation.OperationHelper.validateWriteRequestCollations(OperationHelper.java:182)
at com.mongodb.operation.OperationHelper$4.call(OperationHelper.java:205)
at com.mongodb.operation.OperationHelper.checkBypassDocumentValidationIsSupported(OperationHelper.java:288)
at com.mongodb.operation.OperationHelper.validateWriteRequests(OperationHelper.java:199)
at com.mongodb.operation.MixedBulkWriteOperation$2.call(MixedBulkWriteOperation.java:204)
at com.mongodb.operation.OperationHelper$8.onResult(OperationHelper.java:476)
at com.mongodb.operation.OperationHelper$8.onResult(OperationHelper.java:469)
at com.mongodb.connection.DefaultServer$1.onResult(DefaultServer.java:105)
at com.mongodb.connection.DefaultServer$1.onResult(DefaultServer.java:96)
at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
at com.mongodb.connection.DefaultConnectionPool.openAsync(DefaultConnectionPool.java:188)
at com.mongodb.connection.DefaultConnectionPool.getAsync(DefaultConnectionPool.java:145)
at com.mongodb.connection.DefaultServer.getConnectionAsync(DefaultServer.java:96)
at com.mongodb.binding.AsyncClusterBinding$AsyncClusterBindingConnectionSource.getConnection(AsyncClusterBinding.java:102)
at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:469)
at com.mongodb.operation.OperationHelper.access$000(OperationHelper.java:58)
at com.mongodb.operation.OperationHelper$AsyncCallableWithConnectionCallback.onResult(OperationHelper.java:463)
at com.mongodb.operation.OperationHelper$AsyncCallableWithConnectionCallback.onResult(OperationHelper.java:453)
at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
at com.mongodb.binding.AsyncClusterBinding$1.onResult(AsyncClusterBinding.java:81)
at com.mongodb.binding.AsyncClusterBinding$1.onResult(AsyncClusterBinding.java:75)
at com.mongodb.connection.BaseCluster$ServerSelectionRequest.onResult(BaseCluster.java:409)
at com.mongodb.connection.BaseCluster.handleServerSelectionRequest(BaseCluster.java:280)
at com.mongodb.connection.BaseCluster.selectServerAsync(BaseCluster.java:141)
at com.mongodb.binding.AsyncClusterBinding.getAsyncClusterBindingConnectionSource(AsyncClusterBinding.java:75)
at com.mongodb.binding.AsyncClusterBinding.getWriteConnectionSource(AsyncClusterBinding.java:70)
at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:442)
at com.mongodb.operation.MixedBulkWriteOperation.executeAsync(MixedBulkWriteOperation.java:195)
at com.mongodb.async.client.MongoClientImpl$2.execute(MongoClientImpl.java:140)
at com.mongodb.async.client.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:623)
at com.mongodb.async.client.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:327)
at com.mongodb.reactivestreams.client.internal.MongoCollectionImpl$3.apply(MongoCollectionImpl.java:222)
at com.mongodb.reactivestreams.client.internal.MongoCollectionImpl$3.apply(MongoCollectionImpl.java:219)
at com.mongodb.async.client.SingleResultCallbackSubscription.requestInitialData(SingleResultCallbackSubscription.java:39)
at com.mongodb.async.client.AbstractSubscription.tryRequestInitialData(AbstractSubscription.java:151)
at com.mongodb.async.client.AbstractSubscription.request(AbstractSubscription.java:82)
at com.mongodb.reactivestreams.client.internal.ObservableToPublisher$1$1.request(ObservableToPublisher.java:50)
at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.set(Operators.java:1439)
at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onSubscribe(FluxOnErrorResume.java:67)
at com.mongodb.reactivestreams.client.internal.ObservableToPublisher$1.onSubscribe(ObservableToPublisher.java:39)
at com.mongodb.async.client.SingleResultCallbackSubscription.<init>(SingleResultCallbackSubscription.java:34)
at com.mongodb.async.client.Observables$2.subscribe(Observables.java:76)
at com.mongodb.reactivestreams.client.internal.ObservableToPublisher.subscribe(ObservableToPublisher.java:36)
at reactor.core.publisher.FluxFlatMap.trySubscribeScalarMap(FluxFlatMap.java:169)
at reactor.core.publisher.MonoFlatMapMany.subscribe(MonoFlatMapMany.java:46)
at reactor.core.publisher.FluxOnErrorResume.subscribe(FluxOnErrorResume.java:46)
at reactor.core.publisher.MonoTakeLastOne.subscribe(MonoTakeLastOne.java:48)
at reactor.core.publisher.MonoMapFuseable.subscribe(MonoMapFuseable.java:59)
at reactor.core.publisher.MonoFlatMap.subscribe(MonoFlatMap.java:60)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
at reactor.core.publisher.Mono.subscribe(Mono.java:2757)
at reactor.core.publisher.Mono.subscribeWith(Mono.java:2878)
at reactor.core.publisher.Mono.subscribe(Mono.java:2751)
at reactor.core.publisher.Mono.subscribe(Mono.java:2718)
at reactor.core.publisher.Mono.subscribe(Mono.java:2665)
at fr.app.helios.service.SalesforceIncomingServiceTest.testMongoDbRef(SalesforceIncomingServiceTest.java:73)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
2017-09-19 13:08:09,049 INFO Thread-16 GenericWebApplicationContext.doClose - Closing org.springframework.web.context.support.GenericWebApplicationContext@2e3a5237: startup date [Tue Sep 19 15:08:03 CEST 2017]; root of context hierarchy
2017-09-19 13:08:09,058 INFO Thread-16 connection.info - Closed connection [connectionId{localValue:4, serverValue:85}] to localhost:27017 because the pool has been closed.
2017-09-19 13:08:09,061 INFO Thread-16 connection.info - Closed connection [connectionId{localValue:3, serverValue:84}] to localhost:27017 because the pool has been closed.
Is there a solution or it's bug ?
Thanks
Is there a solution or it's bug ?
It's impossible to tell from what you've provided thus far. Can you please provide a complete, minimal example that we can unzip or git clone that reproduces the problem?
@wilkinsona
spring-boot-2-mongo-dbref-example.zip
You are using a mixture of Mongo Driver 3.4.3 and 3.5.0. You should override the version properties rather than individual dependencies:
<properties>
<mongo-driver-reactivestreams.version>1.6.0</mongo-driver-reactivestreams.version>
<mongodb.version>3.5.0</mongodb.version>
</properties>
I see that :
Caused by: java.lang.ClassNotFoundException: com.mongodb.reactivestreams.client.MongoClient
It's the same for you @wilkinsona ?
No, your test passes for me with the change I described above.
It's strange
I use mongo v3.4.3
Have you an idea for resolve this issue ?
Caused by: java.lang.TypeNotPresentException: Type com.mongodb.reactivestreams.client.MongoClient not present
Caused by: java.lang.ClassNotFoundException: com.mongodb.reactivestreams.client.MongoClient
To be specific, as this may save the day for any other developers..
This error: _CodecConfigurationException: Can't find a codec for class xxx_ means that your mongo driver is not able to handle/parse the data you sent in the object you made of that xxx class and accordingly can't generate the mongo query you want.
The resolution in that case would be either to use the right class (in my case replacing java array by ArrayList resolved the issue).. The other resolution could be to upgrade your driver. This depends on your exact case.
hth
Most helpful comment
To be specific, as this may save the day for any other developers..
This error: _CodecConfigurationException: Can't find a codec for class xxx_ means that your mongo driver is not able to handle/parse the data you sent in the object you made of that xxx class and accordingly can't generate the mongo query you want.
The resolution in that case would be either to use the right class (in my case replacing java array by ArrayList resolved the issue).. The other resolution could be to upgrade your driver. This depends on your exact case.
hth