分享

从Mybatis得到的数据无法转存到MongoDB,无法序列化成BSON

minglic66 发表于 2013-10-17 21:37:41 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 4 17168
最近发现一个让人很纠结的问题,用Mybatis从Mysql数据中将数据读入到Javabean集合里面,然后遍历这个集合想将数据转存到MongoDB,结果发现无法序列化,但如果New一个对象,手工将数据Set进去,又能进行存储,Why?Tel me Why????
注:用的是Spring MongoDB
报错信息如下:
java.lang.IllegalArgumentException: can't serialize class java.lang.Class
        at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:234)
        at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:140)
        at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:190)
        at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:140)
        at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:86)
        at com.mongodb.DefaultDBEncoder.writeObject(DefaultDBEncoder.java:27)
        at com.mongodb.OutMessage.putObject(OutMessage.java:142)
        at com.mongodb.DBApiLayer$MyCollection.update(DBApiLayer.java:346)
        at com.mongodb.DBCollection.update(DBCollection.java:165)
        at com.mongodb.DBCollection.save(DBCollection.java:736)
        at com.mongodb.DBCollection.save(DBCollection.java:703)
        at org.springframework.data.mongodb.core.MongoTemplate$11.doInCollection(MongoTemplate.java:791)
        at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:369)
        at org.springframework.data.mongodb.core.MongoTemplate.saveDBObject(MongoTemplate.java:785)
        at org.springframework.data.mongodb.core.MongoTemplate.doSave(MongoTemplate.java:721)
        at org.springframework.data.mongodb.core.MongoTemplate.save(MongoTemplate.java:708)
        at org.springframework.data.mongodb.core.MongoTemplate.save(MongoTemplate.java:704)
        at com.minephone.mongodb.common.dao.impl.BaseDaoImpl.save(BaseDaoImpl.java:42)
        at com.minephone.community.biz.impl.CountyBizImpl.save(CountyBizImpl.java:26)
        at com.minephone.community.biz.impl.CountyBizImpl.save(CountyBizImpl.java:1)
        at com.minephone.community.CountyTest.mytest(CountyTest.java:26)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
        at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
        at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
        at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
        at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
        at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
              
               
               

已有(4)人评论

跳转到指定楼层
Killer_ZR 发表于 2013-10-17 21:38:36

            最好贴点代码,https://groups.google.com/forum/?fromgroups#!topic/mongodb-user/fhQV81AjEHQ 这个希望对你有帮助
        
回复

使用道具 举报

comaple 发表于 2013-10-17 21:39:09

            Spring MongoDB这个没有用过,但这个问题本人觉得应该是,你的字段中出现了double类型的字段了,或者其他类型的字段使得你的框架不支持。实时去掉一些字段在试一下。
        
回复

使用道具 举报

ITbasketplayer 发表于 2013-10-17 21:39:47

            估计同一个pojo对象无法做到在2个框架中兼容
        
回复

使用道具 举报

fengyun4hao 发表于 2013-10-17 21:40:41

            你的javabean需要继承BasicDBobject
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条