Search code examples
google-app-enginegoogle-cloud-datastorejdojdoql

Why error "Joins are only supported when all filters are 'equals' filters."


I am not sure what am I doning wrong here? It complains "Joins are only supported when all filters are 'equals' filters." when the query is executed. How can I get around that?

Query query = pm.newQuery(ItemInfo.class);

if (lastSyncDate != null) {
    query.declareVariables("DeviceInfo deviceInfo");
    query.setFilter("this.toDevices.contains(deviceInfo) && " +
    "deviceInfo.phoneNumber == numberParam && createdDate > lastSyncDateParam");
    query.declareParameters("String numberParam, java.util.Date lastSyncDateParam");
    map.put("lastSyncDateParam", lastSyncDate);
} else {
    query.declareVariables("DeviceInfo deviceInfo");
    query.setFilter("this.toDevices.contains(deviceInfo) && deviceInfo.phoneNumber == numberParam");

    query.declareParameters("String numberParam");
}
map.put("numberParam", "123456");
query.setOrdering("createdDate desc");

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class ItemInfo {

   @PrimaryKey
   @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
   private Long id;

   @Persistent
   private String number;

   @Persistent
   private List<DeviceInfo> toDevices;
}

Solution

  • App Engine's datastore isn't relational, and doesn't support joins, which you're doing implicitly by using a field on a referenced model. Instead, you should fetch the entity or entities with the given phone number, and use the keys of those entities to filter your result dataset, eliminating the implied join.