Re: Circle references

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Apr 15 2009 - 08:50:45 EDT

  • Next message: Andrey Razumovsky: "Re: Circle references"

    Yeah you described the cause correctly. Now forgetting about Cayenne
    for a sec, is there even a way to save it with just SQL INSERTs
    without violating the constraints?

    Usually there isn't and the commit has to be split into INSERT ...
    VALUES (NULL /* null FK */...) and an UPDATE. Cayenne can't do it
    automatically, so you can either manually split it to 2 transactions,
    or figure a way to configured "deferred constraint checking" on your
    DB (some DB's allow that), or drop the FK constraint for this one
    relationship in DB.

    Andrus

    On Apr 15, 2009, at 3:37 PM, Andrey Razumovsky wrote:

    > Hi,
    >
    > I've got three entities, A, B, and C and three to-one relationships
    > (A->B,
    > B->C, C->A). When I fire code like that:
    >
    > A a = context.newObject(A.class);
    > B b = context.newObject(B.class);
    >
    > a.setToB(b);
    > context.commitChanges();
    >
    > I *sometimes* get SQL exception at commit, saying that object in B
    > does not
    > exist when inserting A, i.e. Cayenne is insering records in wrong
    > order.
    > Seems that it just can't define order of commits because of circle
    > references. Can I somehow help Cayenne solve this puzzle? (I think I
    > can
    > even sacrifice some of reverse (to-many) relationships.
    > And what's the algorithm of sorting entities before commit?
    >
    > Thanks,
    > Andrey



    This archive was generated by hypermail 2.0.0 : Wed Apr 15 2009 - 08:51:19 EDT