datanucleus-rdbms
datanucleus-rdbms copied to clipboard
Support bulk-fetch for 1-N/M-N on not just candidate, but also next level
See also https://github.com/datanucleus/datanucleus-core/issues/189.
In JPA when a FETCH JOIN is specified on a 1-N candidate relation then we use bulk-fetch. In this case in question it is FETCH JOIN via 1-1, then FETCH JOIN via 1-N. The latter is not being retrieved, and hence not detached.
In JDO the same applies where we have a candidate with a 1-N, and an element that has a 1-N with something else.
In terms of an example if we have class A with a Collection<B>
, and class B with a Collection<C>
and we want to bulk fetch the bs and cs when fetching an A, we get
SELECT 'mydomain.model.A' AS DN_TYPE,A0.ID,A0."NAME" FROM A A0
SELECT 'mydomain.model.B' AS DN_TYPE,A1.ID,A1."NAME",A0.ID_OID,A0.IDX AS NUCORDER0
FROM A_BS A0 INNER JOIN B A1 ON A0.ID_EID = A1.ID
WHERE A0.IDX >= 0
AND EXISTS (
SELECT 'mydomain.model.A' AS DN_TYPE,A0_SUB.ID AS DN_APPID
FROM A A0_SUB WHERE A0.ID_OID = A0_SUB.ID
) ORDER BY NUCORDER0
The "problem" in implementing this is that we then need to either expand the second SQL to also add an EXISTS clause on the b.cs field (i.e quite complicated), or do a simple load all Cs for a set of owner Bs.