cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Karich <>
Subject Re: Temporary Objects
Date Fri, 06 Apr 2007 16:15:09 GMT

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