Re: Circle references

From: Andrey Razumovsky (razumovsky.andre..mail.com)
Date: Wed Apr 15 2009 - 09:15:58 EDT

  • Next message: Andrus Adamchik: "Re: Circle references"

    I argee this might be tricky, and right now I'll do this in two commits.
    But:
    there is a way to determine the order. At least when I'm inserting tables to
    two tables only (i.e. the circle is incomplete). We could determine the
    order using only tables where there are dirty records...

    2009/4/15 Andrus Adamchik <andru..bjectstyle.org>

    > 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 - 09:16:30 EDT