Re: Problems with extra N+1 requests - likely due to poor mapping defns, but not sure how to rectify


Andy
 
Edited

With a single object relation with the FK at the selected object side there are only 3 things that would be feasible.
  1. Load the related object, instantiating it. Put it in the fetch plan for this
  2. Don't load the related object and leave for lazy loading. JDO default.
  3. Include the PK (FK) field(s) in the SQL, and just store them some where and maybe use them later if required.
DataNucleus (and the JDO API also for that matter) allows options 1 and 2. Specification is explicit.

If you always want to load the related object with just the PK field(s) then you can always mark it as "fetch-fk-only" on that field, in the metadata.
If you only sometimes want to load the related object with just the PK fields, then put the field in the fetch plan for the SELECT, but also remove all other fields of the related object from the fetch plan (so it doesn't add a join to the related object).

Join main@datanucleus.groups.io to automatically receive all group messages.