Re: Temporary Objects

From: Mike Kienenberger (mkienen..mail.com)
Date: Tue Apr 10 2007 - 10:19:13 EDT

  • Next message: peter karich: "Re: Temporary Objects"

    I don't think you're going to find a good solution to this problem.

    Here's one thing you can try, though.

    Keep in your Entity classes two lists of objects. Add a second
    "non-persistent" list for managing your non-persistent objects in
    addition to the standard one for persistent objects. Then change
    your accessors so that they merge both lists and return that as the
    result.

    Thus, your app will see the merged list, but the Cayenne layer would
    only see the persistent object lists.

    On 4/6/07, Peter Karich <peatha..ahoo.de> wrote:
    > Hallo!
    >
    > I am back with some problems related to the discussion on 27 March. [1]
    >
    > It is clear that my approach is memory consuming:
    > "Collecting all nonpersistent objects in a list, which are registered,
    > to avoid NullPointerException's. And on a commit I will remove them."
    >
    > Another problem is that removing them before committing is not secure,
    > because I could run in a NPE, if somewhere else in my code is a
    > reference to that nonpersistent object (if I call e.g. setToOneTarget on
    > that obj)
    >
    > I think I can do the unregistering in the finalize() method of each
    > nonpersistent object. But cayenne holds all objects in memory before
    > committing, right?
    > So finalize will never be called...
    > And so decide to create a second datacontext for the temporary objects.
    >
    > But I can't point from a temporary object to an object from the other
    > dataContext, right?
    >
    >
    > So what should I do?
    > I simply want to mix persistent and nonpersistent objects.
    > (they have ToOne and ToMany relations)
    > But without large memory consumption and NPE's.
    >
    > Every comment and idea will help :-)
    >
    > Thank you, Peter.
    >
    >
    >
    >
    > [1] Mike wrote:
    > Temporary is unregistered. Or marked as deleted but registered.
    > Your workaround seems reasonable.
    >
    > On 3/27/07, Peter Karich <peatha..ahoo.de> wrote:
    > >
    > > > Your second problem (trying to add references to non-persistent
    > > > objects to a persistent object) is a hard one. If you post what
    > > > you're trying to do specifically, maybe someone can suggest an
    > > > alternate design pattern. By default, Cayenne attempts to initialize
    > > > persistence if it finds a non-persisted object being added to the
    > > > object graph. Maybe the solution is to construct your non-persisted
    > > > objects in a "COMMITTED" state so that Cayenne doesn't have issues
    > > > with them.
    > >
    > > Nothing specifically. I want to use all my TimeInterval's with
    > > attributes and 2 "toOneTargets" although they are not registered (is
    > > this *temporary* or is "registered but not commited" *temporary*?)
    > > My workaround is to collect all not registered objects in a list and
    > > register them. Before commiting I unregister them.
    > >
    > > Peter.
    >



    This archive was generated by hypermail 2.0.0 : Tue Apr 10 2007 - 10:19:50 EDT