cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Kienenberger" <>
Subject Re: Temporary Objects
Date Tue, 10 Apr 2007 14:19:13 GMT
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

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 <> 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 <> 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.

View raw message