Search code examples
google-cloud-datastoreobjectify

When are Ref's loaded when making a query in Datastore with Objectify?


If I have a @Load Ref<Driver> in my entity Car and I make a query for Cars, when are those refs actually loaded from the datastore?

For example, in the code below are the Driver's loaded from the datastore when this query runs? Or are they loaded when I return the Cars at the end of my endpoint and it is serialized?

// The Query itself is Iterable
Query<Car> q = ofy().load().type(Car.class).filter("vin >", "123456789");
for (Car car: q) {
    System.out.println(car.toString());
}

Solution

  • If you have the @Load annotation, Refs are loaded for each chunk of iteration. So if your chunk size is 30, then as each chunk of 30 cars is loaded their drivers will be loaded.

    If you remove the @Load annotation, each Ref is loaded separately on demand.