I am trying to get data from MYSQL and after processing saving it in MongoDB using java app. My POJO contains java.util.date objects to store date fields. When i fetch from MYSQL it returns java.sql.date object. hence my pojo will have reference of sql date in util date object.
using spring data mongodb i am saving same pojo in mongodb. where it raises below exception:
Exception in thread "main" org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class java.sql.Date.
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:210)
at com.mongodb.DBObjectCodec.encodeMap(DBObjectCodec.java:220)
at com.mongodb.DBObjectCodec.writeValue(DBObjectCodec.java:196)
at com.mongodb.DBObjectCodec.encodeIterable(DBObjectCodec.java:269)
at com.mongodb.DBObjectCodec.writeValue(DBObjectCodec.java:198)
at com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:128)
at com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:61)
at com.mongodb.CompoundDBObjectCodec.encode(CompoundDBObjectCodec.java:48)
at com.mongodb.CompoundDBObjectCodec.encode(CompoundDBObjectCodec.java:27)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:63)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:29)
at com.mongodb.connection.UpdateCommandMessage.writeTheWrites(UpdateCommandMessage.java:85)
at com.mongodb.connection.UpdateCommandMessage.writeTheWrites(UpdateCommandMessage.java:42)
at com.mongodb.connection.BaseWriteCommandMessage.encodeMessageBodyWithMetadata(BaseWriteCommandMessage.java:118)
at com.mongodb.connection.RequestMessage.encodeWithMetadata(RequestMessage.java:160)
at com.mongodb.connection.WriteCommandProtocol.sendMessage(WriteCommandProtocol.java:199)
at com.mongodb.connection.WriteCommandProtocol.execute(WriteCommandProtocol.java:88)
at com.mongodb.connection.UpdateCommandProtocol.execute(UpdateCommandProtocol.java:63)
at com.mongodb.connection.UpdateCommandProtocol.execute(UpdateCommandProtocol.java:37)
at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:159)
at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:260)
at com.mongodb.connection.DefaultServerConnection.updateCommand(DefaultServerConnection.java:121)
at com.mongodb.operation.UpdateOperation.executeCommandProtocol(UpdateOperation.java:76)
at com.mongodb.operation.BaseWriteOperation$1.call(BaseWriteOperation.java:111)
at com.mongodb.operation.BaseWriteOperation$1.call(BaseWriteOperation.java:106)
at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:187)
at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:178)
at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:106)
at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:58)
at com.mongodb.Mongo.execute(Mongo.java:769)
at com.mongodb.Mongo$2.execute(Mongo.java:752)
at com.mongodb.DBCollection.executeWriteOperation(DBCollection.java:330)
at com.mongodb.DBCollection.replaceOrInsert(DBCollection.java:408)
at com.mongodb.DBCollection.save(DBCollection.java:397)
at com.mongodb.DBCollection.save(DBCollection.java:370)
at org.springframework.data.mongodb.core.MongoTemplate$11.doInCollection(MongoTemplate.java:1040)
at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:462)
at org.springframework.data.mongodb.core.MongoTemplate.saveDBObject(MongoTemplate.java:1035)
at org.springframework.data.mongodb.core.MongoTemplate.doSave(MongoTemplate.java:975)
at org.springframework.data.mongodb.core.MongoTemplate.save(MongoTemplate.java:921)
at com.persivia.ptf.mongo.dao.impl.MongoDaoImpl.save(MongoDaoImpl.java:47)
now how i can save it in mongodb without changing my dao classes.