0

I am having trouble figuring out if GCP Datastore supports querying nested properties of an entity.

My use case right now is like so:

Module
  -> Application

Module

enter image description here

Application

enter image description here

@Entity
class Module {
  Long id;

  @Reference
  Applicaiton application;
}
@Entity
class Application {
  Long id;
  String name;
}

I want to try query the module based on its nested Application name. I have tried providing the filter like so without success:

Query<? extends BaseEntity> query = Query.newEntityQueryBuilder()
    .setKind("module") 
    .setFilter(PropertyFilter.eq("application.name", "UserApp"))
    .build();

I'm using Springs GCP datastore abstraction through their DatastoreTemplate, but this doesn't seem related given that when I try run the GQL on the GCP console I get no results back either.

SELECT * FROM module WHERE application.name = "UserApp"

Thanks for taking the time to read through this. Any help with this is greatly appreciated!

Ben Dol
  • 427
  • 6
  • 18
  • Hi @BenDol I would recommend you to check the official documentation [here](https://cloud.google.com/datastore/docs/concepts/queries#datastore-datastore-run-query-java) to check the differences between your queries and the official ones. Could you also, please, check and see if individually, you can query their data correctly? – gso_gabriel Aug 06 '20 at 12:13
  • Hi @gso_gabriel, I have already done both of the things you've suggested before coming to Stackoverflow for help. The answer is yes I have checked for differences, there are none and yes data can be queried individually from each kind. – Ben Dol Aug 06 '20 at 20:35

1 Answers1

2

It looks like you are using a Reference and not an embedded entity. The Application in module is really a key reference to an Application entity. Thus the values of application are not an indexed on the Module entity.

Jim Morrison
  • 2,784
  • 1
  • 7
  • 11