The Fetch Policy can be used to optimize your object graph. Onyx enables developers to load only what they need. There are instances when users would like to reduce the size of the object graph in order to save memory and network overhead by lazily or not loading relationships.
|Eager fetch policy will hydrate the entire relationship and all of the subsequent object graph.|
|Lazy fetch policy will return references to the relationship data. When referenced using the List interface, the relationship will be lazily filled in.|
|The relationship will not be populated upon fetching an entity. It will sometimes be populated in the event the entity is already cached.|
You can download the code for this example here:
For this example all of the relationships have CascadePolicy of CascadePolicy.SAVE or CascadePolicy.ALL. This is to ensure the entire object graph is persisted.