This post is to document the way to add filters programmatically rather than declaratively (in binding files).
Let’s start with a declarative configuration.
Note that the mapping defined the entity of type Parent with a reference to a list of entities of type Child. Each Child points to its Parent.
Note also that there are actually two filters – the entity-level filter applies to queries to type Parent and the association-level filter applies to queries involving the list of dependant entities.
The entity-level filter is available on the mapping object easily:
However, to get the association-level filter you have to dig deeper to get the properties of type Bag from the actual mapping: