1

我编写了一个代码,其中包含嵌入了测试用例信息的套件信息。我编写了 TestCase.java 和 Suite.java,它们似乎没有错误。但是使用我编写的 MongoMapper.java 我得到了这个错误。Morphia 类型中的 fromDBObject(Class, BasicDBObject) 方法不适用于参数 (Class, DBObject)。请帮我解决这个问题,并建议我如何查看我的集合是否在 MongoDB Shell 中更新。谢谢提前。这是我的代码。

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());



    }
}

我得到的错误是 Morphia 类型的 fromDBObject(Class, BasicDBObject) 方法不适用于参数 (Class, DBObject)

4

1 回答 1

0

看起来您正在使用此更改之前的 Morphia 版本:http ://code.google.com/p/morphia/issues/detail?id=15

您可以尝试将 DrAssistReport.findOne() 的返回值转换为“BasicDBObject”,或者将您正在使用的 Morphia 版本升级到其 Morphia.fromDBObject 方法采用 DBObject 而不是需要 BasicDBObject 的版本。

于 2012-08-14T02:39:53.437 回答