Re: New objects break FK constraints

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Jan 29 2004 - 20:11:47 EST

  • Next message: Andrus Adamchik: "Re: New objects break FK constraints"

    On Jan 29, 2004, at 11:41 AM, Jim Menard wrote:

    > Andrus,
    >
    >> Ordering of operations has been around for a while and proved to be
    >> very stable. I am fairly sure there is something with the mapping of
    >> the relationship (DB constraints and Cayenne mapping do not match).
    >> Is this the case described here:
    >> http://objectstyle.org/jira/secure/ViewIssue.jspa?key=CAY-41
    >
    > No, it's different. The Member table has a FK to BillAccount, but the
    > BillAccount does not directly refer to the member at all.
    >
    > There is one more class in the mix: Address. Each address has a
    > nullable FK back to the member. Maybe that's causing the problem? I
    > need to write a simple test case to see what's going on.

    Now that I have a DataMap to look at, I se what is happening. Entities
    have a circular dependency: Address depends on Member, Member depends
    on BillAccount, BillAccount depends on Address:

    Address -> Member -> BillAccount -> Address

    So ordering can't be resolved just by analyzing entity dependencies. Of
    course it can be resolved at the row level - if Address belongs to
    BillAccount, it should be inserted first, if it belongs to a Member -
    it should be inserted last.

    Cayenne doesn't handle such relationship cycles yet. On the other hand
    the case that Arndt mentioned - entities with simple reflexive
    relationships - seems to be handled in the code. Andriy may know better
    if it has any more limitations, since he wrote it, but from what I see
    parent-child relationships in the same table should be sorted properly.

    But regardless of this limitation, I think the schema can be redesigned
    to remove the cycle. member.bill_account_id can be substituted with
    bill_account.member_id. If I understand it correctly, a bill_account
    always belongs to a single member, right? It is not shared by multiple
    people?

    Andrus



    This archive was generated by hypermail 2.0.0 : Thu Jan 29 2004 - 20:11:55 EST