字段“ClassName”由morphia插入mongodb

时间:2018-06-11 05:27:52

标签: java mongodb morphia classname

我想将复杂对象保存为另一个对象的属性:

@Entity(noClassnameStored = true)
public class User {
    ......
    @Embedded
    public Map<String, List<Order>> orders; 
    ......

}

@Embedded
public class Order {

   String productName;
   String description;
..........

}

使用setter在代码中设置map:

Map<String, List<Order>> ordersMap = new HashMap<>();
ordersMap.put(...);
user.setOrders(ordersMap);

但在文档&#39; User&#39;每个订单都保存在字段&#39; className&#39;在地图&#39;订单&#39; :

&#34; 1&#34; :[{&#34; className&#34;:&#34; com.domain.Order&#34;,        &#34; PRODUCTNAME&#34; :&#34; Milk&#34;,        &#34;描述&#34;:&#34; Fresh&#34;        }      ]

如何不保存字段&#39; className&#39;对于ordersMap内的订单?

0 个答案:

没有答案