Shwetanka
Shwetanka

Reputation: 5036

Querying for @Embedded map in objectify for GAE

Please consider following sample

@Entity
public class Abc {
    @Id
    private Long id;

    @Unindexed
    private String name;

    @Embedded
    private Map<String, Xyz> objs;
}

public class Xyz {
    private String objName;
    private String objStatus;
}

Now I want the object of Abc such that objs.get("someKey").getObjName().equals("someName") is true.

How do I make this query in Objectify? Also, if I store 'objs' as list instead of map, can I query for an object of Abc such that one of the list values have objName as 'someName'? Need help in this. Thanks

Upvotes: 4

Views: 1214

Answers (1)

Martin Probst
Martin Probst

Reputation: 9641

You should be able to query like this:

Objectify ofy = factory.begin
ofy.query(Abc.class).filter("objs.someKey.objName=", "someName")

The map keys are simple folded into the map of properties of the entity, using a dot as the separator and the name of the map field ("objs") as a prefix to avoid collisions.

Upvotes: 2

Related Questions