rrrocky
rrrocky

Reputation: 696

Cannot find field in mongo collection using morphia

I have an abstract Scala class as a Mongo collection.

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

Another class extends the above

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

There are some docs of GroupACLTemplate in the collection. I am trying a simple query

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

This throws a ValidationException

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

I do not think it is because of the long standing polymorphism issue in morphia. Because when I try to access just groupRoleAccess, it is able to. However, it is not able to access inside that set. It is a normal Java set. This is the GroupRoleAccess class

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

Am I missing something here?

Upvotes: 0

Views: 1183

Answers (2)

rrrocky
rrrocky

Reputation: 696

I managed to hack something up. Apparently, since the collection is an abstract class, Mongo/Morphia does not look for attributes that are present in its subclasses. So I used createQuery and passed the class of the subclass.

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

But I still wonder how it was able to extract groupRoleAccess before

Upvotes: 1

evanchooly
evanchooly

Reputation: 6233

You should try 1.3.0-SNAPSHOT. I just fixed a bug similar to this and it probably fixes your issue, too.

Upvotes: 0

Related Questions