gpt4 book ai didi

java - 使用吗啡无法在 mongo 集合中找到字段

转载 作者:行者123 更新时间:2023-12-01 09:42:07 25 4
gpt4 key购买 nike

我有一个抽象的 Scala 类作为 Mongo 集合。

@Entity("aclTemplate")
abstract class AclTemplate(@(Id@field) var id: String) extends Serializable

另一个类扩展了上面的

@Entity("aclTemplate")
class GroupACLTemplate(id: String, var groupRoleAccess: Set[GroupRoleAccess]) extends AclTemplate(id) with Serializable

集合中有一些GroupACLTemplate的文档。我正在尝试一个简单的查询

createQuery().disableValidation().field("groupRoleAccess.groupId").equal(groupId).asList();

这会抛出一个 ValidationException

org.mongodb.morphia.query.ValidationException: The field 'groupRoleAccess.groupId' could not be found in 'com.model.acl.AclTemplate'

我不认为这是因为吗啡长期存在的多态性问题。因为当我尝试仅访问groupRoleAccess时,它就能够访问。但是,它无法访问该集合内部。这是一个普通的Java集合。这是GroupRoleAccess

class GroupRoleAccess(var groupId: String, var roleId: String) extends Serializable

我在这里遗漏了什么吗?

最佳答案

我成功破解了一些东西。显然,由于集合是一个抽象类,Mongo/Morphia 不会查找其子类中存在的属性。所以我使用了createQuery并传递了子类的类。

ds.createQuery(clazz).disableValidation().field("groupRoleAccess.groupId").equal(groupId).asList();

但我仍然想知道它之前是如何提取groupRoleAccess

关于java - 使用吗啡无法在 mongo 集合中找到字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38370493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com