2012-08-03 33 views
1

我已经编写了一个代码,其中包含嵌入了Test Case信息的Suite信息。编写了TestCase.java和Suite.java,它们似乎没有错误。但是用我写的MongoMapper.java,我得到了这个错误。 来自Morphia类型的DBObject(Class,BasicDBObject)的方法不适用于参数(Class,DBObject)。请亲自帮助我解决这个问题,并向我建议如何查看我是否已在MongoDB Shell中更新我的集合。谢谢提前。这是我的代码。Morphia错误:类型Morphia中来自DBObject(类<T>,BasicDBObject)的方法不适用于参数(类<Suite>,DBObject)

package com.DrAssist.Morphia.model; 
import com.google.code.morphia.Morphia; 
import com.mongodb.DB; 
import com.mongodb.DBCollection; 
import com.mongodb.Mongo; 
import org.junit.After; 
import org.junit.Before; 
import org.junit.Test; 

import java.net.UnknownHostException; 
import static junit.framework.Assert.assertNotNull; 
import static junit.framework.Assert.assertNull; 

public class MongoMapper { 
    Morphia morph; 
    Mongo mongo; 
    DBCollection DrAssistReport; 
    @Before 
    public void setUp() throws UnknownHostException { 
    morph = new Morphia(); 
    mongo = new Mongo("127.0.0.1", 27017); 
    // This is where we map Persons and addresses 
    // But shouldn't the annotation be able to handle that? 
    morph.map(Suite.class).map(TestCase.class); 
    DB testDb = mongo.getDB("test"); 
    DrAssistReport = testDb.getCollection("DrAssistReport"); 
    } 

    @Test 
    public void storePersonThroughMorphiaMapping() { 

    Suite suite = new Suite(new TestCase("1",new String[]{"Test1", "Test2", "Test3", "Test4"},"1","5","6","7","889")); 
    suite.setSID("1"); 
    suite.setsuiteName("Suite1"); 
    suite.setnoOfTests("5"); 


    DrAssistReport.save(morph.toDBObject(suite)); 
    Suite suite2 = morph.fromDBObject(Suite.class, DrAssistReport.findOne()); 
    assertNotNull(suite2.getSID()); 



    } 
} 

我得到的错误是在类型的方法fromDBObject(类,BasicDBObject)吗啡是不适用的参数(类,DBOBJECT)

回答

0

它看起来像你使用的版本从此变化之前的Morphia:http://code.google.com/p/morphia/issues/detail?id=15

您可以尝试将DrAssistReport.findOne()的返回值转换为“BasicDBObject”或将Morphia的版本升级到Morphia.fromDBObject方法所采用的版本一个DBObject而不需要一个BasicDBObject。

相关问题