Hi I am using Objectify and I have the following:
public static final Key<A> TopParent = new Key<A>(A.class,1)
class A {
}
class B {
@Parent
Key parent;
Key referenceKeyToC
}
class C {
@Parent
Key parent;
}
I am then trying to get ALL B-objects in an TRANSACTION with Ancestor(TopParent) and some Reference Key C – but it keep returning 0 elements.
This is my query:
List> bKeys = oft.query(B.class).ancestor(TopParent).filter(“referenceKeyToC”, new Key(C.class), b.referenceKeyToC).listKeys();
When I SAVE B it has BOTH parent and referenceKeyToC set correctly ..
IF I run the Query without the Key Filter like:
List> bKeys = oft.query(B.class).ancestor(TopParent).listKeys();
It returns all the B-objects – and those B-objects all Contains their referenceKeyToC
Any ideas??
Jesper
This is almost certainly an indexing issue. In order for that query to work, you must define two indexes:
In Objectify 3.x, properties have single-property indexes by default, but if you have added @Unindexed to the class B then you need to put @Indexed on referenceKeyToC.
The multi-property index is defined in datastore-indexes.xml. If you run this query in dev mode, the environment should provide you with the snippet of xml needed.