To query fields in a nested object with CQEngine, you generally need to put the logic to read the nested value inside your Attribute, not inside your query. This way the attribute will expose the nested field to your queries as if it was a regular/non-nested kind of field.
You can find an example of how to write an attribute by hand to read nested fields in this related question.
Generating attributes automatically
If you are using AttributeBytecodeGenerator
to auto-generate attributes, then be aware that it is not designed to generate attributes for fields in nested objects. It generates attributes for fields in POJOs only (Plain Old Java Objects).
If your object contains nested objects, then technically it's not really a POJO and it's more like an object graph.
This isn't a limitation of AttributeBytecodeGenerator
that's likely to be fixed actually, because graphs can contain one-to-many or many-to-many relationships. It typically takes a human to decide how a graph should be traversed to extract meaningful values from nested objects.
If you take a look at the hand-written attribute in the question I linked above, consider that it actually implements quite a complex graph traversal algorithm to fetch nested values just for that particular attribute. So AttributeBytecodeGenerator
does not attempt to do this.
Specifying paths to nested values in queries
You might then wonder why we (or rather CQEngine) cannot specify the path to nested values in queries instead. This relates to performance.
CQEngine requires the path through an object graph to nested values, to be specified statically (programmatically) inside the Attribute, because this is the only way that indexes can be built over those nested values.
If this was not the case, and the paths to nested values were only supplied in queries, then it would not be possible to build indexes over nested values in advance. So the only way to answer the queries would be to do a brute-force scan through the entire collection.
So it is beneficial performance-wise to specify how nested values should be read in attributes, as it allows nested values to be indexed.
Summary
The TL;DR is: If you absolutely need to use complex objects with CQEngine, I'm afraid you will probably need to write attributes to read the nested vales by hand! The other alternative is to refactor or flatten your object graphs into actual POJOs. Hope that helps!