2012-09-21 44 views
1

我有以下結構。 產品嵌入在商店中;並且評論嵌入在產品中。Morphia添加項目到嵌入式

1- Store 
    2-Products[]--> 
    3-Reviews[] 

我想用下面的代碼添加一個新的項目來審查。它不會給我一個錯誤,但它也不會添加它。

Query q1=ds.createQuery(Product.class).filter("Code", code); 
if(q1.countAll()==1) 
    { 
    ops = ds.createUpdateOperations(Product.class).add("Reviews", review); 
    ds.update(q1, ops); 
    } 

回答

0

我想通了。唯一的問題是查詢嵌入式產品,通過添加新評論並使用ds.CreateUpdateOperations()更新該產品來修改它。Set(ops)