What is the best way to fetch complex entities extremely shallowly: only a name field, the id and version?
The normal way we work is by fetching primitive fields eagerly (which is the default), marking our relations as LAZY and making FetchGroups for them to be used in FetchPlans. One solution I can think of is marking each and every primitive field as LAZY and make a fetchgroup that contains them all. But this gives some code clutter and is not very maintainable: we should not forget to map each new field as lazy and include it in the FetchGroup. Also all previous FetchPlans should now include this new FetchGroup. Should we call entityManager.getFetchPlan().clearFetchGroups() to clear everything and then simply add the name field? I think this has the drawback that we should not forget to do this in each query that involves the same entity. Would it be possible to have a FetchGroup that specifies fields that should NOT to be fetched instead of fields to be fetched? Our use case: we have a Customer and Contact (a person) that have a many-to-many relation between them. We wish to be able to fetch a Contact with all its Customers but only need the Customer names and nothing more so that performance is better. Bonus question: Is it possible to set a fetch plan such that we fetch a Customer (deeply: with some relations to other entities), fetch its Contacts and for each of these Contacts fetch the Customers with ONLY their names??? A use case for this is a GUI for editing one Customer together with its Contacts and be able to see for each Contact that it is used in other Customers as well. Regards, Henno Vermeulen
