Search code examples
objectify

Do you need to use limit(1) when using first() to load an entity in objectify?


If you use the first() method such as:

Car car = ofy().load().type(Car.class).filter("vin", "123456789").first().now();

Do you need to use limit(1) like this Car car = ofy().load().type(Car.class).filter("vin", "123456789").limit(1).first().now(); to make sure only one entity is loaded (instead of loading all entities that match the query)? Or will the first() method ensure only one entity will be queried for?


Solution

  • first() automatically applies a limit(1).

    Don't be shy about navigating to the implementations in your IDE. In IntelliJ, Navigate -> Method Hierarchy is very helpful.