datanucleus-core icon indicating copy to clipboard operation
datanucleus-core copied to clipboard

Support storage/retrieval of embedded objects with collections of non-embedded persistables

Open andyjefferson opened this issue 8 years ago • 0 comments

Take these classes

@PersistenceCapable
public class A
{
    B b;
}

@PersistenceCapable(embeddedOnly="true")
public class B
{
    Collection<C> elements;
}

@PersistenceCapable
public class C
{
}

so we have tables A and C, with B embedded into table A. The table C would need to have a FK across to table A for "b.elements".

Firstly, with RDBMS, we dont allow this since don't currently handle the "b.elements" as the SCO store to enable use to navigate across the FK, and we don't provide for creation of the FK in C back to A.

We also currently have an assumption that when we retrieve an embedded object that it is fully loaded (all fields). If we allow fields containing non-embedded (persistable) objects then this breaks down. When we do A a = em.find(A.class, id); if the object is in the L2 cache then it pulls in all fields, since all are present in the L2 cache. If it isn't in the L2 cache then it will pull in the fields loadable in the basic FetchRequest (i.e all except the Collection of C). This is never recovered from since it thinks the field is loaded (StateManager.initForEmbedded). Which in turn populates the L2 cache with an object without the nested Collection etc.

andyjefferson avatar Dec 14 '16 19:12 andyjefferson