Re: missing toOne

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Sat Jul 17 2004 - 22:16:04 EDT

  • Next message: Scott McClure: "Re: [DONE] Re: Simple retrieval of an object by PK"

    Back to this 2 month-old issue. This is indeed an existing problem. The
    right solution will require some mapping redesign. So at the moment if
    you have this issue in your code, play with "to dep pk" setting. This
    should be a good workaround. For details see:

          http://objectstyle.org/jira/secure/ViewIssue.jspa?key=CAY-132

    What I did now is changing the implementation of
    CayenneDataObject.resolveFault() from current (clearly incorrect)
    behavior of quietly making object TRANSIENT to the one that does that,
    but also throws a CayenneRuntimeException, so that the users are aware
    of what's going on.

    So if you see new CayenneRuntimeExceptions after upgrading to the
    upcoming B2, that simply indicates an already existing problem that was
    overlooked before.

    If you think that exception is a bad idea, you can always override
    "resolveFault" in subclass. In addition if you want to get fancy,
    DataContextDelegate.shouldProcessDelete() and finishedProcessDelete()
    methods are notified right before the exception is thrown.

    Andrus

    On May 27, 2004, at 11:07 AM, Mike Kienenberger wrote:
    > Andrus Adamchik <andru..bjectstyle.org> wrote:
    >>
    >> On May 27, 2004, at 4:56 AM, Tore Halset wrote:
    >>
    >>> Hello!
    >>>
    >>> My model has a to-one relation A->B that sometimes are empty. Is that
    >>> supported? How can I test if a B exist for a given A? Checking for
    >>> (a.getB() == null) does not work. It seems like a.getB returns a
    >>> empty
    >>> object with every attribute set to null.
    >>>
    >>> Regards,
    >>> - Tore.
    >>
    >> Tore,
    >>
    >> I remember this used to be a bug in the past, but this should've been
    >> fixed long time ago. "a.getB() == null" should work. So the question
    >> is
    >> - what version of Cayenne are you using? And also how is the
    >> relationship mapped?
    >
    >
    > I have a similar situation where I allow admin users to view a
    > "deleted"
    > record in some situations (we mark records "invalidated"=true rather
    > than
    > actually delete data, then the application's restricting qualifiers
    > automatically hide these records from the view of the application).
    >
    > This is how I detect and handle such a dangling one-to-one.
    >
    > PaymentMethod aPaymentMethod =
    > aPaymentHistory.getPaymentMethod();
    > aPaymentMethod.resolveFault();
    > if (PersistenceState.TRANSIENT !=
    > aPaymentMethod.getPersistenceState()) // then it exists
    > else // it doesn't exist
    >
    > This is used under 1.1M5, I believe.
    >
    > -Mike



    This archive was generated by hypermail 2.0.0 : Sat Jul 17 2004 - 22:16:12 EDT