2016-07-14 35 views
0

我有一个抽象的Scala类作为Mongo集合。使用吗啡在mongo集合中找不到字段

@Entity("aclTemplate") 
abstract class AclTemplate(@([email protected]) 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 

我在这里错过了什么吗?

回答

0

您应该尝试1.3.0-SNAPSHOT。我只是修复了一个类似于此的错误,它也可能解决您的问题。

+0

没有,没有工作 – rockydgeekgod

0

我设法解决了一些问题。显然,由于集合是一个抽象类,因此Mongo/Morphia不会查找其子类中存在的属性。所以我用createQuery并通过了子类的类。

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

但我仍然不知道它是怎么能够提取groupRoleAccess

相关问题