MongoDB jodatime:org.bson.codecs.configuration.CodecConfigurationException:找不到 class org.joda.time.DateTime 的编解码器
MongoDB jodatime: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class org.joda.time.DateTime
我的代码:
DateTime dateTime = new DateTime();
BasicDBObject oldDoc = new BasicDBObject("email",email);
BasicDBObject newDoc = new BasicDBObject("$set",new BasicDBObject("office_move_date",dateTime.toDateTime()));
collection.update(oldDoc,newDoc);
错误信息:
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8413)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access00(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent4(GlassViewEventHandler.java:417)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null8(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)
... 48 more Caused by: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class org.joda.time.DateTime.
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.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:37)
at com.mongodb.DBObjectCodec.writeValue(DBObjectCodec.java:212)
at com.mongodb.DBObjectCodec.encodeMap(DBObjectCodec.java:222)
at com.mongodb.DBObjectCodec.writeValue(DBObjectCodec.java:198)
at com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:130)
at com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:61)
at org.bson.BsonDocumentWrapper.getUnwrapped(BsonDocumentWrapper.java:195)
at org.bson.BsonDocumentWrapper.isEmpty(BsonDocumentWrapper.java:115)
at com.mongodb.operation.BulkWriteBatch$WriteRequestEncoder.encode(BulkWriteBatch.java:389)
at com.mongodb.operation.BulkWriteBatch$WriteRequestEncoder.encode(BulkWriteBatch.java:371)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:63)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:29)
at com.mongodb.connection.BsonWriterHelper.writeDocument(BsonWriterHelper.java:74)
at com.mongodb.connection.BsonWriterHelper.writePayload(BsonWriterHelper.java:58)
at com.mongodb.connection.BsonWriterHelper.writePayloadArray(BsonWriterHelper.java:50)
at com.mongodb.connection.SplittablePayloadBsonWriter.writeEndDocument(SplittablePayloadBsonWriter.java:53)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:118)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:41)
at com.mongodb.connection.CommandMessage.addDocumentWithPayload(CommandMessage.java:166)
at com.mongodb.connection.CommandMessage.encodeMessageBodyWithMetadata(CommandMessage.java:148)
at com.mongodb.connection.RequestMessage.encode(RequestMessage.java:145)
at com.mongodb.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:245)
at com.mongodb.connection.UsageTrackingInternalConnection.sendAndReceive(UsageTrackingInternalConnection.java:98)
at com.mongodb.connection.DefaultConnectionPool$PooledConnection.sendAndReceive(DefaultConnectionPool.java:441)
at com.mongodb.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:76)
at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:189)
at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:263)
at com.mongodb.connection.DefaultServerConnection.command(DefaultServerConnection.java:126)
at com.mongodb.operation.MixedBulkWriteOperation.executeCommand(MixedBulkWriteOperation.java:373)
at com.mongodb.operation.MixedBulkWriteOperation.executeBulkWriteBatch(MixedBulkWriteOperation.java:255)
at com.mongodb.operation.MixedBulkWriteOperation.access0(MixedBulkWriteOperation.java:66)
at com.mongodb.operation.MixedBulkWriteOperation.call(MixedBulkWriteOperation.java:199)
at com.mongodb.operation.MixedBulkWriteOperation.call(MixedBulkWriteOperation.java:190)
at com.mongodb.operation.OperationHelper.withReleasableConnection(OperationHelper.java:432)
at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:190)
at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:147)
at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:52)
at com.mongodb.Mongo.execute(Mongo.java:833)
at com.mongodb.Mongo.execute(Mongo.java:814)
at com.mongodb.DBCollection.executeWriteOperation(DBCollection.java:341)
at com.mongodb.DBCollection.update(DBCollection.java:563)
at com.mongodb.DBCollection.update(DBCollection.java:486)
at com.mongodb.DBCollection.update(DBCollection.java:463)
at com.mongodb.DBCollection.update(DBCollection.java:441)
at com.mongodb.DBCollection.update(DBCollection.java:505)
at com.mongodb.DBCollection.update(DBCollection.java:520)
at com.application.Menu.officeMove.ControllerOfficeMove.confirmBtnClicked(ControllerOfficeMove.java:76)
... 58 more
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent4(GlassViewEventHandler.java:417)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null8(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)
... 48 more Caused by: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class org.joda.time.DateTime.
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.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:37)
at com.mongodb.DBObjectCodec.writeValue(DBObjectCodec.java:212)
at com.mongodb.DBObjectCodec.encodeMap(DBObjectCodec.java:222)
at com.mongodb.DBObjectCodec.writeValue(DBObjectCodec.java:198)
at com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:130)
at com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:61)
at org.bson.BsonDocumentWrapper.getUnwrapped(BsonDocumentWrapper.java:195)
at org.bson.BsonDocumentWrapper.isEmpty(BsonDocumentWrapper.java:115)
at com.mongodb.operation.BulkWriteBatch$WriteRequestEncoder.encode(BulkWriteBatch.java:389)
at com.mongodb.operation.BulkWriteBatch$WriteRequestEncoder.encode(BulkWriteBatch.java:371)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:63)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:29)
at com.mongodb.connection.BsonWriterHelper.writeDocument(BsonWriterHelper.java:74)
at com.mongodb.connection.BsonWriterHelper.writePayload(BsonWriterHelper.java:58)
at com.mongodb.connection.BsonWriterHelper.writePayloadArray(BsonWriterHelper.java:50)
at com.mongodb.connection.SplittablePayloadBsonWriter.writeEndDocument(SplittablePayloadBsonWriter.java:53)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:118)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:41)
at com.mongodb.connection.CommandMessage.addDocumentWithPayload(CommandMessage.java:166)
at com.mongodb.connection.CommandMessage.encodeMessageBodyWithMetadata(CommandMessage.java:148)
at com.mongodb.connection.RequestMessage.encode(RequestMessage.java:145)
at com.mongodb.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:245)
at com.mongodb.connection.UsageTrackingInternalConnection.sendAndReceive(UsageTrackingInternalConnection.java:98)
at com.mongodb.connection.DefaultConnectionPool$PooledConnection.sendAndReceive(DefaultConnectionPool.java:441)
at com.mongodb.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:76)
at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:189)
at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:263)
at com.mongodb.connection.DefaultServerConnection.command(DefaultServerConnection.java:126)
at com.mongodb.operation.MixedBulkWriteOperation.executeCommand(MixedBulkWriteOperation.java:373)
at com.mongodb.operation.MixedBulkWriteOperation.executeBulkWriteBatch(MixedBulkWriteOperation.java:255)
at com.mongodb.operation.MixedBulkWriteOperation.access0(MixedBulkWriteOperation.java:66)
at com.mongodb.operation.MixedBulkWriteOperation.call(MixedBulkWriteOperation.java:199)
at com.mongodb.operation.MixedBulkWriteOperation.call(MixedBulkWriteOperation.java:190)
at com.mongodb.operation.OperationHelper.withReleasableConnection(OperationHelper.java:432)
at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:190)
at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:147)
at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:52)
at com.mongodb.Mongo.execute(Mongo.java:833)
at com.mongodb.Mongo.execute(Mongo.java:814)
at com.mongodb.DBCollection.executeWriteOperation(DBCollection.java:341)
at com.mongodb.DBCollection.update(DBCollection.java:563)
at com.mongodb.DBCollection.update(DBCollection.java:486)
at com.mongodb.DBCollection.update(DBCollection.java:463)
at com.mongodb.DBCollection.update(DBCollection.java:441)
at com.mongodb.DBCollection.update(DBCollection.java:505)
at com.mongodb.DBCollection.update(DBCollection.java:520)
at com.application.Menu.officeMove.ControllerOfficeMove.confirmBtnClicked(ControllerOfficeMove.java:76)
... 58 more
如何将日期从 dateTime.toDateTime() 变量添加到 mongodb?
不支持 Joda 你必须使用 java.util.Date
instead, so if you already use Joda or java.time
library of Java 8 you have to convert it to java.util.Date
在你的情况下你可以使用 :
getJodaDateTime();//Your dateTime
java.util.Date utilDate = getJodaDateTime().toDate();//Convert it to java.util.Date
BasicDBObject newDoc = new BasicDBObject("$set",
new BasicDBObject("office_move_date", utilDate)
);
但在您的情况下,将 org.joda.time.DateTime
转换为 java.util.Date
没有任何意义,您可以直接使用 java.util.Date
:
BasicDBObject newDoc = new BasicDBObject("$set",
new BasicDBObject("office_move_date", new java.util.Date())//<--- Use just this
);
我的代码:
DateTime dateTime = new DateTime();
BasicDBObject oldDoc = new BasicDBObject("email",email);
BasicDBObject newDoc = new BasicDBObject("$set",new BasicDBObject("office_move_date",dateTime.toDateTime()));
collection.update(oldDoc,newDoc);
错误信息:
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8413)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access00(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent4(GlassViewEventHandler.java:417)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null8(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)
... 48 more Caused by: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class org.joda.time.DateTime.
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.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:37)
at com.mongodb.DBObjectCodec.writeValue(DBObjectCodec.java:212)
at com.mongodb.DBObjectCodec.encodeMap(DBObjectCodec.java:222)
at com.mongodb.DBObjectCodec.writeValue(DBObjectCodec.java:198)
at com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:130)
at com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:61)
at org.bson.BsonDocumentWrapper.getUnwrapped(BsonDocumentWrapper.java:195)
at org.bson.BsonDocumentWrapper.isEmpty(BsonDocumentWrapper.java:115)
at com.mongodb.operation.BulkWriteBatch$WriteRequestEncoder.encode(BulkWriteBatch.java:389)
at com.mongodb.operation.BulkWriteBatch$WriteRequestEncoder.encode(BulkWriteBatch.java:371)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:63)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:29)
at com.mongodb.connection.BsonWriterHelper.writeDocument(BsonWriterHelper.java:74)
at com.mongodb.connection.BsonWriterHelper.writePayload(BsonWriterHelper.java:58)
at com.mongodb.connection.BsonWriterHelper.writePayloadArray(BsonWriterHelper.java:50)
at com.mongodb.connection.SplittablePayloadBsonWriter.writeEndDocument(SplittablePayloadBsonWriter.java:53)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:118)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:41)
at com.mongodb.connection.CommandMessage.addDocumentWithPayload(CommandMessage.java:166)
at com.mongodb.connection.CommandMessage.encodeMessageBodyWithMetadata(CommandMessage.java:148)
at com.mongodb.connection.RequestMessage.encode(RequestMessage.java:145)
at com.mongodb.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:245)
at com.mongodb.connection.UsageTrackingInternalConnection.sendAndReceive(UsageTrackingInternalConnection.java:98)
at com.mongodb.connection.DefaultConnectionPool$PooledConnection.sendAndReceive(DefaultConnectionPool.java:441)
at com.mongodb.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:76)
at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:189)
at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:263)
at com.mongodb.connection.DefaultServerConnection.command(DefaultServerConnection.java:126)
at com.mongodb.operation.MixedBulkWriteOperation.executeCommand(MixedBulkWriteOperation.java:373)
at com.mongodb.operation.MixedBulkWriteOperation.executeBulkWriteBatch(MixedBulkWriteOperation.java:255)
at com.mongodb.operation.MixedBulkWriteOperation.access0(MixedBulkWriteOperation.java:66)
at com.mongodb.operation.MixedBulkWriteOperation.call(MixedBulkWriteOperation.java:199)
at com.mongodb.operation.MixedBulkWriteOperation.call(MixedBulkWriteOperation.java:190)
at com.mongodb.operation.OperationHelper.withReleasableConnection(OperationHelper.java:432)
at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:190)
at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:147)
at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:52)
at com.mongodb.Mongo.execute(Mongo.java:833)
at com.mongodb.Mongo.execute(Mongo.java:814)
at com.mongodb.DBCollection.executeWriteOperation(DBCollection.java:341)
at com.mongodb.DBCollection.update(DBCollection.java:563)
at com.mongodb.DBCollection.update(DBCollection.java:486)
at com.mongodb.DBCollection.update(DBCollection.java:463)
at com.mongodb.DBCollection.update(DBCollection.java:441)
at com.mongodb.DBCollection.update(DBCollection.java:505)
at com.mongodb.DBCollection.update(DBCollection.java:520)
at com.application.Menu.officeMove.ControllerOfficeMove.confirmBtnClicked(ControllerOfficeMove.java:76)
... 58 more
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent4(GlassViewEventHandler.java:417)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null8(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)
... 48 more Caused by: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class org.joda.time.DateTime.
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.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:37)
at com.mongodb.DBObjectCodec.writeValue(DBObjectCodec.java:212)
at com.mongodb.DBObjectCodec.encodeMap(DBObjectCodec.java:222)
at com.mongodb.DBObjectCodec.writeValue(DBObjectCodec.java:198)
at com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:130)
at com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:61)
at org.bson.BsonDocumentWrapper.getUnwrapped(BsonDocumentWrapper.java:195)
at org.bson.BsonDocumentWrapper.isEmpty(BsonDocumentWrapper.java:115)
at com.mongodb.operation.BulkWriteBatch$WriteRequestEncoder.encode(BulkWriteBatch.java:389)
at com.mongodb.operation.BulkWriteBatch$WriteRequestEncoder.encode(BulkWriteBatch.java:371)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:63)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:29)
at com.mongodb.connection.BsonWriterHelper.writeDocument(BsonWriterHelper.java:74)
at com.mongodb.connection.BsonWriterHelper.writePayload(BsonWriterHelper.java:58)
at com.mongodb.connection.BsonWriterHelper.writePayloadArray(BsonWriterHelper.java:50)
at com.mongodb.connection.SplittablePayloadBsonWriter.writeEndDocument(SplittablePayloadBsonWriter.java:53)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:118)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:41)
at com.mongodb.connection.CommandMessage.addDocumentWithPayload(CommandMessage.java:166)
at com.mongodb.connection.CommandMessage.encodeMessageBodyWithMetadata(CommandMessage.java:148)
at com.mongodb.connection.RequestMessage.encode(RequestMessage.java:145)
at com.mongodb.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:245)
at com.mongodb.connection.UsageTrackingInternalConnection.sendAndReceive(UsageTrackingInternalConnection.java:98)
at com.mongodb.connection.DefaultConnectionPool$PooledConnection.sendAndReceive(DefaultConnectionPool.java:441)
at com.mongodb.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:76)
at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:189)
at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:263)
at com.mongodb.connection.DefaultServerConnection.command(DefaultServerConnection.java:126)
at com.mongodb.operation.MixedBulkWriteOperation.executeCommand(MixedBulkWriteOperation.java:373)
at com.mongodb.operation.MixedBulkWriteOperation.executeBulkWriteBatch(MixedBulkWriteOperation.java:255)
at com.mongodb.operation.MixedBulkWriteOperation.access0(MixedBulkWriteOperation.java:66)
at com.mongodb.operation.MixedBulkWriteOperation.call(MixedBulkWriteOperation.java:199)
at com.mongodb.operation.MixedBulkWriteOperation.call(MixedBulkWriteOperation.java:190)
at com.mongodb.operation.OperationHelper.withReleasableConnection(OperationHelper.java:432)
at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:190)
at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:147)
at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:52)
at com.mongodb.Mongo.execute(Mongo.java:833)
at com.mongodb.Mongo.execute(Mongo.java:814)
at com.mongodb.DBCollection.executeWriteOperation(DBCollection.java:341)
at com.mongodb.DBCollection.update(DBCollection.java:563)
at com.mongodb.DBCollection.update(DBCollection.java:486)
at com.mongodb.DBCollection.update(DBCollection.java:463)
at com.mongodb.DBCollection.update(DBCollection.java:441)
at com.mongodb.DBCollection.update(DBCollection.java:505)
at com.mongodb.DBCollection.update(DBCollection.java:520)
at com.application.Menu.officeMove.ControllerOfficeMove.confirmBtnClicked(ControllerOfficeMove.java:76)
... 58 more
如何将日期从 dateTime.toDateTime() 变量添加到 mongodb?
不支持 Joda 你必须使用 java.util.Date
instead, so if you already use Joda or java.time
library of Java 8 you have to convert it to java.util.Date
在你的情况下你可以使用 :
getJodaDateTime();//Your dateTime
java.util.Date utilDate = getJodaDateTime().toDate();//Convert it to java.util.Date
BasicDBObject newDoc = new BasicDBObject("$set",
new BasicDBObject("office_move_date", utilDate)
);
但在您的情况下,将 org.joda.time.DateTime
转换为 java.util.Date
没有任何意义,您可以直接使用 java.util.Date
:
BasicDBObject newDoc = new BasicDBObject("$set",
new BasicDBObject("office_move_date", new java.util.Date())//<--- Use just this
);