Morphia/MongoDB:访问“嵌入”来自 @Embedded 对象的对象
我有一个与此类似的 Morphia 架构:(
@Entity
class BlogEntry {
@Embedded
List<BlogComment> comments
}
@Embedded
class BlogComment {
String content
Long authorId
}
上面的代码仅用于说明)
我正在尝试获取特定的 BlogComment,以便用新内容更新它。我有相应的 BlogEntry 对象可用,并且有authorId,就这个问题而言,这两个对象一起足以唯一地标识正确的 BlogComment。
我的问题是,BlogComment 没有显式包含对其“父”BlogEntry 对象的引用,那么如何编写吗啡查询来检索此 BlogComment?像这样的东西:
//fetch the unique comment corresponding to this blog entry and this author ID.
BlogComment comment = ds.find(BlogComment.class, "blogEntryId =", blogEntry.id)
.filter("authorId", authorId)
.get();
I have a Morphia schema similar to this one:
@Entity
class BlogEntry {
@Embedded
List<BlogComment> comments
}
@Embedded
class BlogComment {
String content
Long authorId
}
(code above just for illustration)
I'm trying to get a specific BlogComment in order to update it with new content. I have the corresponding BlogEntry object available, and I have the authorId, which let's say for the purposes of this question that these two together are sufficient to uniquely identify the correct BlogComment.
My question is, BlogComment does not explicitly contain a reference to its "parent" BlogEntry object, so how can I write a morphia query to retrieve this BlogComment? Something like:
//fetch the unique comment corresponding to this blog entry and this author ID.
BlogComment comment = ds.find(BlogComment.class, "blogEntryId =", blogEntry.id)
.filter("authorId", authorId)
.get();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
既然您已经有了博客条目对象,为什么不使用简单的 Java 循环来过滤它呢?
Since you already have the blog entry object why not use a simple Java loop to filter it out?