You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Tad <ta...@gmail.com> on 2012/02/23 00:53:01 UTC

Deleting object in one-to-many relationship leaves transient

We're using Cayenne in a web application. Our relationship is like this:

root <- one-to-many -> children

We make a POST request, loop through some objects, and delete some using
ObjectContext.deleteObject. We then commit, no exceptions are thrown, and
ObjectContext.uncommittedObjects is empty. The DB reflects these changes.

We then redirect to a page that lists the remaining objects. However, when
using the generated root.getChildrenArray() method, it returns a list that
includes the objects which were just deleted. These objects are marked as
transient.

Is my understanding correct that we need to perform an explicit query in
order to refresh this list, rather than using the generated getter?

Thanks for any help.

--
Thanks,
Tad

Re: Deleting object in one-to-many relationship leaves transient

Posted by Tad <ta...@gmail.com>.
Thanks! We did figure out a fix on our own; setting the "nullify" delete
rule on the relationship from child to parent fixes the issue.

Really, "nullify" should be the default... but I digress.

--
Thanks,
Tad

On Wed, Feb 22, 2012 at 2:35 PM, Michael Gentry <mg...@masslight.net>wrote:

> Hi Tad,
>
> I always remove the object from the relationship (unlinking it) and
> then delete it.  Try doing that instead of just deleting it.
>
> mrg
>
>
> On Wed, Feb 22, 2012 at 6:53 PM, Tad <ta...@gmail.com> wrote:
> > We're using Cayenne in a web application. Our relationship is like this:
> >
> > root <- one-to-many -> children
> >
> > We make a POST request, loop through some objects, and delete some using
> > ObjectContext.deleteObject. We then commit, no exceptions are thrown, and
> > ObjectContext.uncommittedObjects is empty. The DB reflects these changes.
> >
> > We then redirect to a page that lists the remaining objects. However,
> when
> > using the generated root.getChildrenArray() method, it returns a list
> that
> > includes the objects which were just deleted. These objects are marked as
> > transient.
> >
> > Is my understanding correct that we need to perform an explicit query in
> > order to refresh this list, rather than using the generated getter?
> >
> > Thanks for any help.
> >
> > --
> > Thanks,
> > Tad
>

Re: Deleting object in one-to-many relationship leaves transient

Posted by Michael Gentry <mg...@masslight.net>.
Hi Tad,

I always remove the object from the relationship (unlinking it) and
then delete it.  Try doing that instead of just deleting it.

mrg


On Wed, Feb 22, 2012 at 6:53 PM, Tad <ta...@gmail.com> wrote:
> We're using Cayenne in a web application. Our relationship is like this:
>
> root <- one-to-many -> children
>
> We make a POST request, loop through some objects, and delete some using
> ObjectContext.deleteObject. We then commit, no exceptions are thrown, and
> ObjectContext.uncommittedObjects is empty. The DB reflects these changes.
>
> We then redirect to a page that lists the remaining objects. However, when
> using the generated root.getChildrenArray() method, it returns a list that
> includes the objects which were just deleted. These objects are marked as
> transient.
>
> Is my understanding correct that we need to perform an explicit query in
> order to refresh this list, rather than using the generated getter?
>
> Thanks for any help.
>
> --
> Thanks,
> Tad