我有一个抽象的 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/