2012-05-04 112 views

回答

2

假设博客帖子实体可以有多个评论,但每个评论只属于一个博客帖子。

首先,您需要删除参考:

BlogPostEntity blog = mongoDataStore.find(BlogEntity.class) 
    .field("comments") 
    .hasThisElement(new Key<CommentEntity>(CommentEntity.class, comment.getId())) 
    .get(); 
if (blog != null) { 
    blog.removeComment(comment); // Assuming you have a remove method for that, otherwise use the setter 
    persist(blog); // Assuming you have a generic persist method 
} 

然后你就可以删除实体本身:

mongoDataStore.delete(comment);