Reputation: 19416
I am using objectify 3.1 on appengine and attempting to do a ancestor query. I want to fetch all the children of an object that are of a certain kind. Below is my code:
@Cached
@Entity
public class Car {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String make;
private String model;
}
@Cached
@Entity
public class Tire {
@Id
public String keyName;
@Parent Key<Car> car;
private String brand;
private String size;
}
My query is this code:
List<Tire> list= ofy.query(Tire.class).ancestor(new Key<Car(Car.class,carID))).list();
When I create the tire objects I use this code to set the relationship:
newTire.setCar(new Key<Car>(Car.class,Car.getID()));
I know the Parent relationship is there because I can query for it in the datastore admin and it shows the parent in the decoded entity key:
Decoded entity key: Car: id=135172 > Tire: name=myCarUniqueID
This query always returns 0 results, and it seems like I have followed all the best practices on the objectify website. Any help would be appreciated!
Upvotes: 2
Views: 2230
Reputation: 80330
Your code looks ok, so the only thing that might be wrong is a non-existing carID
.
The Objectify javadoc listed on the site is actually for trunk version which is a forthcoming Objectify 4. What you need to look at is Objectify 3.1 javadoc: this version has fetch()
on the query.
Also, @GeneratedValue
is not an Objectify annotation.
Upvotes: 2