Grokbase Groups Cayenne user May 2006
FAQ
I don't know if it is related or not, but I've also had problems in the
past when I try to create a new parent and several child objects related
to that parent all at once and then try to commit. The problem looks
like Cayenne is INSERTing the child records into the database first,
before the parent record, and the database complains that the children
have an invalid foreign key (and, yes, I have the ON UPDATE and ON
DELETE rules for the foreign key set to DO NOTHING and I still get the
error from PostgreSQL). To get around it I just committed the parent
first, then committed all the children.

Thanks,
Jeff

Search Discussions

  • Tomi NA at May 20, 2006 at 6:32 am

    On 5/20/06, Jeff de Vries wrote:
    I don't know if it is related or not, but I've also had problems in the
    past when I try to create a new parent and several child objects related
    to that parent all at once and then try to commit. The problem looks
    like Cayenne is INSERTing the child records into the database first,
    before the parent record, and the database complains that the children
    have an invalid foreign key (and, yes, I have the ON UPDATE and ON
    DELETE rules for the foreign key set to DO NOTHING and I still get the
    error from PostgreSQL). To get around it I just committed the parent
    first, then committed all the children.
    I had the same problem, IIRC: I was very surprised that cayenne
    couldn't handle such a commit, although truth be told, I can't imagine
    everything that's going on under the hood of the operation that would
    make implementing this feature difficult.
    I would certainly love to see this fixed (if at all possible) as I
    wasn't to happy to have to commit in the middle of what had to be an
    atomic transaction. It'd also make the framework a lot more flexible,
    e.g. enabling the user to have long inter-commit sessions with complex
    data updates, if the user so desires.

    t.n.a.
  • Marcin Skladaniec at May 20, 2006 at 7:01 am
    Hm. Strange. I do really complex commits, sometimes 7 or more related
    records (I mean 7 levels of relationship, not seven entities),
    related by many-to-many many-to-one relationships and never get those
    problems. And it doesn't matter if the records are new or old. Could
    you describe how you are creating objects and how do you commit them ?

    Regards
    Marcin
    On 20/05/2006, at 4:31 PM, Tomi NA wrote:
    On 5/20/06, Jeff de Vries wrote:
    I don't know if it is related or not, but I've also had problems
    in the
    past when I try to create a new parent and several child objects
    related
    to that parent all at once and then try to commit. The problem looks
    like Cayenne is INSERTing the child records into the database first,
    before the parent record, and the database complains that the
    children
    have an invalid foreign key (and, yes, I have the ON UPDATE and ON
    DELETE rules for the foreign key set to DO NOTHING and I still get
    the
    error from PostgreSQL). To get around it I just committed the parent
    first, then committed all the children.
    I had the same problem, IIRC: I was very surprised that cayenne
    couldn't handle such a commit, although truth be told, I can't imagine
    everything that's going on under the hood of the operation that would
    make implementing this feature difficult.
    I would certainly love to see this fixed (if at all possible) as I
    wasn't to happy to have to commit in the middle of what had to be an
    atomic transaction. It'd also make the framework a lot more flexible,
    e.g. enabling the user to have long inter-commit sessions with complex
    data updates, if the user so desires.

    t.n.a.
  • Andrus Adamchik at May 21, 2006 at 5:24 pm
    Cayenne handles correct ordering of operations automatically, based
    on dependencies derived from relationships.The algorithm has a few
    limitations though. It can't handle cycles (when Entity A depends on
    Entity B, but also Entity B depends on Entity A). This probably also
    includes entities that have relationships to the same entity (I
    assume this is the case the original post was referring to).

    There are few solutions:

    1. (a workaround, rather than a solution) Do commit in two steps.
    2. Define FK constraints in question as DEFERRABLE and INITIALLY
    DEFERRED (supported by Postgres 8.*)
    3. Set a custom org.objectstyle.cayenne.map.EntitySorter on the
    DataNode.

    Andrus

    On May 20, 2006, at 3:00 AM, Marcin Skladaniec wrote:

    Hm. Strange. I do really complex commits, sometimes 7 or more
    related records (I mean 7 levels of relationship, not seven
    entities), related by many-to-many many-to-one relationships and
    never get those problems. And it doesn't matter if the records are
    new or old. Could you describe how you are creating objects and how
    do you commit them ?

    Regards
    Marcin
    On 20/05/2006, at 4:31 PM, Tomi NA wrote:
    On 5/20/06, Jeff de Vries wrote:
    I don't know if it is related or not, but I've also had problems
    in the
    past when I try to create a new parent and several child objects
    related
    to that parent all at once and then try to commit. The problem
    looks
    like Cayenne is INSERTing the child records into the database first,
    before the parent record, and the database complains that the
    children
    have an invalid foreign key (and, yes, I have the ON UPDATE and ON
    DELETE rules for the foreign key set to DO NOTHING and I still
    get the
    error from PostgreSQL). To get around it I just committed the
    parent
    first, then committed all the children.
    I had the same problem, IIRC: I was very surprised that cayenne
    couldn't handle such a commit, although truth be told, I can't
    imagine
    everything that's going on under the hood of the operation that would
    make implementing this feature difficult.
    I would certainly love to see this fixed (if at all possible) as I
    wasn't to happy to have to commit in the middle of what had to be an
    atomic transaction. It'd also make the framework a lot more flexible,
    e.g. enabling the user to have long inter-commit sessions with
    complex
    data updates, if the user so desires.

    t.n.a.
  • Jeff de Vries at May 21, 2006 at 7:05 pm
    Yes, I have cyclical references, so that is probably what is happening.
    I tried setting DEFERRABLE and INITIALLY DEFERRED before, but was still
    getting errors from PostgreSQL (which was very frustrating since I had
    said INITIALLY DEFERRABLE but PostgreSQL was complaining about an
    invalid foreign key as soon as I inserted the child record but before I
    did the commit). I just went back and looked at the last case where
    this was happening and saw that I did not set INITIALLY DEFERRED and
    DEFERRABLE (probably because I gave up after the last time I tried).
    I'll try setting these again and see what happens.

    Thanks for the help!
    Jeff

    Andrus Adamchik wrote:
    Cayenne handles correct ordering of operations automatically, based on
    dependencies derived from relationships.The algorithm has a few
    limitations though. It can't handle cycles (when Entity A depends on
    Entity B, but also Entity B depends on Entity A). This probably also
    includes entities that have relationships to the same entity (I assume
    this is the case the original post was referring to).

    There are few solutions:

    1. (a workaround, rather than a solution) Do commit in two steps.
    2. Define FK constraints in question as DEFERRABLE and INITIALLY
    DEFERRED (supported by Postgres 8.*)
    3. Set a custom org.objectstyle.cayenne.map.EntitySorter on the DataNode.

    Andrus

    On May 20, 2006, at 3:00 AM, Marcin Skladaniec wrote:

    Hm. Strange. I do really complex commits, sometimes 7 or more related
    records (I mean 7 levels of relationship, not seven entities),
    related by many-to-many many-to-one relationships and never get those
    problems. And it doesn't matter if the records are new or old. Could
    you describe how you are creating objects and how do you commit them ?

    Regards
    Marcin
    On 20/05/2006, at 4:31 PM, Tomi NA wrote:
    On 5/20/06, Jeff de Vries wrote:
    I don't know if it is related or not, but I've also had problems in
    the
    past when I try to create a new parent and several child objects
    related
    to that parent all at once and then try to commit. The problem looks
    like Cayenne is INSERTing the child records into the database first,
    before the parent record, and the database complains that the children
    have an invalid foreign key (and, yes, I have the ON UPDATE and ON
    DELETE rules for the foreign key set to DO NOTHING and I still get the
    error from PostgreSQL). To get around it I just committed the parent
    first, then committed all the children.
    I had the same problem, IIRC: I was very surprised that cayenne
    couldn't handle such a commit, although truth be told, I can't imagine
    everything that's going on under the hood of the operation that would
    make implementing this feature difficult.
    I would certainly love to see this fixed (if at all possible) as I
    wasn't to happy to have to commit in the middle of what had to be an
    atomic transaction. It'd also make the framework a lot more flexible,
    e.g. enabling the user to have long inter-commit sessions with complex
    data updates, if the user so desires.

    t.n.a.
  • Jeff de Vries at May 21, 2006 at 7:13 pm
    Going back and looking at my code, I see that a two step commit is fine
    in this particular case since the initially committed items can stand on
    their own without any inconsistencies. I'll try setting the INITIALLY
    DEFERRED and DEFERRABLE constraints anyway to see what happens.

    Andrus Adamchik wrote:
    Cayenne handles correct ordering of operations automatically, based on
    dependencies derived from relationships.The algorithm has a few
    limitations though. It can't handle cycles (when Entity A depends on
    Entity B, but also Entity B depends on Entity A). This probably also
    includes entities that have relationships to the same entity (I assume
    this is the case the original post was referring to).

    There are few solutions:

    1. (a workaround, rather than a solution) Do commit in two steps.
    2. Define FK constraints in question as DEFERRABLE and INITIALLY
    DEFERRED (supported by Postgres 8.*)
    3. Set a custom org.objectstyle.cayenne.map.EntitySorter on the DataNode.

    Andrus

    On May 20, 2006, at 3:00 AM, Marcin Skladaniec wrote:

    Hm. Strange. I do really complex commits, sometimes 7 or more related
    records (I mean 7 levels of relationship, not seven entities),
    related by many-to-many many-to-one relationships and never get those
    problems. And it doesn't matter if the records are new or old. Could
    you describe how you are creating objects and how do you commit them ?

    Regards
    Marcin
    On 20/05/2006, at 4:31 PM, Tomi NA wrote:
    On 5/20/06, Jeff de Vries wrote:
    I don't know if it is related or not, but I've also had problems in
    the
    past when I try to create a new parent and several child objects
    related
    to that parent all at once and then try to commit. The problem looks
    like Cayenne is INSERTing the child records into the database first,
    before the parent record, and the database complains that the children
    have an invalid foreign key (and, yes, I have the ON UPDATE and ON
    DELETE rules for the foreign key set to DO NOTHING and I still get the
    error from PostgreSQL). To get around it I just committed the parent
    first, then committed all the children.
    I had the same problem, IIRC: I was very surprised that cayenne
    couldn't handle such a commit, although truth be told, I can't imagine
    everything that's going on under the hood of the operation that would
    make implementing this feature difficult.
    I would certainly love to see this fixed (if at all possible) as I
    wasn't to happy to have to commit in the middle of what had to be an
    atomic transaction. It'd also make the framework a lot more flexible,
    e.g. enabling the user to have long inter-commit sessions with complex
    data updates, if the user so desires.

    t.n.a.
  • Jeff de Vries at May 22, 2006 at 8:44 pm
    Setting INITIALLY DEFERRED and DEFERRABLE seems to work (now).

    Thanks!
    Jeff

    On May 21, 2006, at 12:12 PM, Jeff de Vries wrote:

    Going back and looking at my code, I see that a two step commit is
    fine in this particular case since the initially committed items
    can stand on their own without any inconsistencies. I'll try
    setting the INITIALLY DEFERRED and DEFERRABLE constraints anyway to
    see what happens.

    Andrus Adamchik wrote:
    Cayenne handles correct ordering of operations automatically,
    based on dependencies derived from relationships.The algorithm has
    a few limitations though. It can't handle cycles (when Entity A
    depends on Entity B, but also Entity B depends on Entity A). This
    probably also includes entities that have relationships to the
    same entity (I assume this is the case the original post was
    referring to).

    There are few solutions:

    1. (a workaround, rather than a solution) Do commit in two steps.
    2. Define FK constraints in question as DEFERRABLE and INITIALLY
    DEFERRED (supported by Postgres 8.*)
    3. Set a custom org.objectstyle.cayenne.map.EntitySorter on the
    DataNode.

    Andrus

    On May 20, 2006, at 3:00 AM, Marcin Skladaniec wrote:

    Hm. Strange. I do really complex commits, sometimes 7 or more
    related records (I mean 7 levels of relationship, not seven
    entities), related by many-to-many many-to-one relationships and
    never get those problems. And it doesn't matter if the records
    are new or old. Could you describe how you are creating objects
    and how do you commit them ?

    Regards
    Marcin
    On 20/05/2006, at 4:31 PM, Tomi NA wrote:
    On 5/20/06, Jeff de Vries wrote:
    I don't know if it is related or not, but I've also had
    problems in the
    past when I try to create a new parent and several child
    objects related
    to that parent all at once and then try to commit. The problem
    looks
    like Cayenne is INSERTing the child records into the database
    first,
    before the parent record, and the database complains that the
    children
    have an invalid foreign key (and, yes, I have the ON UPDATE and ON
    DELETE rules for the foreign key set to DO NOTHING and I still
    get the
    error from PostgreSQL). To get around it I just committed the
    parent
    first, then committed all the children.
    I had the same problem, IIRC: I was very surprised that cayenne
    couldn't handle such a commit, although truth be told, I can't
    imagine
    everything that's going on under the hood of the operation that
    would
    make implementing this feature difficult.
    I would certainly love to see this fixed (if at all possible) as I
    wasn't to happy to have to commit in the middle of what had to
    be an
    atomic transaction. It'd also make the framework a lot more
    flexible,
    e.g. enabling the user to have long inter-commit sessions with
    complex
    data updates, if the user so desires.

    t.n.a.
  • Borut Bolčina at Oct 9, 2006 at 1:44 pm
    Hi,

    in API docs for org.objectstyle.cayenne.map.AshwoodEntitySorter it says:

    "...Presently it works for acyclic database schemas with possible
    multi-reflexive tables. The class uses topological sorting from the
    Ashwood library <http://objectstyle.org/ashwood/>."

    What are multi-reflexive tables? I guess not every reflexive
    relationship is cyclic. If db row "points" to the same db row then it
    would be cyclic (for example - someone is his/her own manager),
    otherwise just reflexive. Is this correct?

    -Borut
    On 21.5.2006 19:24, Andrus Adamchik wrote:
    Cayenne handles correct ordering of operations automatically, based on
    dependencies derived from relationships.The algorithm has a few
    limitations though. It can't handle cycles (when Entity A depends on
    Entity B, but also Entity B depends on Entity A). This probably also
    includes entities that have relationships to the same entity (I assume
    this is the case the original post was referring to).

    There are few solutions:

    1. (a workaround, rather than a solution) Do commit in two steps.
    2. Define FK constraints in question as DEFERRABLE and INITIALLY
    DEFERRED (supported by Postgres 8.*)
    3. Set a custom org.objectstyle.cayenne.map.EntitySorter on the DataNode.

    Andrus

    On May 20, 2006, at 3:00 AM, Marcin Skladaniec wrote:

    Hm. Strange. I do really complex commits, sometimes 7 or more related
    records (I mean 7 levels of relationship, not seven entities),
    related by many-to-many many-to-one relationships and never get those
    problems. And it doesn't matter if the records are new or old. Could
    you describe how you are creating objects and how do you commit them ?

    Regards
    Marcin
    On 20/05/2006, at 4:31 PM, Tomi NA wrote:
    On 5/20/06, Jeff de Vries wrote:
    I don't know if it is related or not, but I've also had problems in
    the
    past when I try to create a new parent and several child objects
    related
    to that parent all at once and then try to commit. The problem looks
    like Cayenne is INSERTing the child records into the database first,
    before the parent record, and the database complains that the children
    have an invalid foreign key (and, yes, I have the ON UPDATE and ON
    DELETE rules for the foreign key set to DO NOTHING and I still get the
    error from PostgreSQL). To get around it I just committed the parent
    first, then committed all the children.
    I had the same problem, IIRC: I was very surprised that cayenne
    couldn't handle such a commit, although truth be told, I can't imagine
    everything that's going on under the hood of the operation that would
    make implementing this feature difficult.
    I would certainly love to see this fixed (if at all possible) as I
    wasn't to happy to have to commit in the middle of what had to be an
    atomic transaction. It'd also make the framework a lot more flexible,
    e.g. enabling the user to have long inter-commit sessions with complex
    data updates, if the user so desires.

    t.n.a.
    --
    bLOG <http://www.delo.si/blog/borutb/>
    --
    Naključna *izjava tedna* iz tednika Mladina:
  • Andrus Adamchik at Oct 11, 2006 at 12:57 am
    Good question :-) Andriy, our math geek, is no longer with us. I
    don't recall the details (need to dig through Ashwood I guess), but
    simple parent/child relationships within the same table used to work
    afaik... We may think of smarter strategies to resolve the cycles
    (such as a chain of insert/update queries in the same transaction)...
    I don't think this will happen soon though.

    Andrus


    On Oct 9, 2006, at 9:43 AM, Borut Bolčina wrote:
    Hi,

    in API docs for org.objectstyle.cayenne.map.AshwoodEntitySorter it
    says:
    "...Presently it works for acyclic database schemas with possible
    multi-reflexive tables. The class uses topological sorting from the
    Ashwood library."
    What are multi-reflexive tables? I guess not every reflexive
    relationship is cyclic. If db row "points" to the same db row then
    it would be cyclic (for example - someone is his/her own manager),
    otherwise just reflexive. Is this correct?

    -Borut
    On 21.5.2006 19:24, Andrus Adamchik wrote:
    Cayenne handles correct ordering of operations automatically,
    based on dependencies derived from relationships.The algorithm has
    a few limitations though. It can't handle cycles (when Entity A
    depends on Entity B, but also Entity B depends on Entity A). This
    probably also includes entities that have relationships to the
    same entity (I assume this is the case the original post was
    referring to).

    There are few solutions:

    1. (a workaround, rather than a solution) Do commit in two steps.
    2. Define FK constraints in question as DEFERRABLE and INITIALLY
    DEFERRED (supported by Postgres 8.*)
    3. Set a custom org.objectstyle.cayenne.map.EntitySorter on the
    DataNode.

    Andrus

    On May 20, 2006, at 3:00 AM, Marcin Skladaniec wrote:

    Hm. Strange. I do really complex commits, sometimes 7 or more
    related records (I mean 7 levels of relationship, not seven
    entities), related by many-to-many many-to-one relationships and
    never get those problems. And it doesn't matter if the records
    are new or old. Could you describe how you are creating objects
    and how do you commit them ?

    Regards
    Marcin
    On 20/05/2006, at 4:31 PM, Tomi NA wrote:
    On 5/20/06, Jeff de Vries wrote:
    I don't know if it is related or not, but I've also had
    problems in the
    past when I try to create a new parent and several child
    objects related
    to that parent all at once and then try to commit. The problem
    looks
    like Cayenne is INSERTing the child records into the database
    first,
    before the parent record, and the database complains that the
    children
    have an invalid foreign key (and, yes, I have the ON UPDATE and ON
    DELETE rules for the foreign key set to DO NOTHING and I still
    get the
    error from PostgreSQL). To get around it I just committed the
    parent
    first, then committed all the children.
    I had the same problem, IIRC: I was very surprised that cayenne
    couldn't handle such a commit, although truth be told, I can't
    imagine
    everything that's going on under the hood of the operation that
    would
    make implementing this feature difficult.
    I would certainly love to see this fixed (if at all possible) as I
    wasn't to happy to have to commit in the middle of what had to
    be an
    atomic transaction. It'd also make the framework a lot more
    flexible,
    e.g. enabling the user to have long inter-commit sessions with
    complex
    data updates, if the user so desires.

    t.n.a.
    --
    <blog-logo.gif>

    --
    Naključna izjava tedna iz tednika Mladina:
  • Andrus Adamchik at Oct 11, 2006 at 1:11 am

    On Oct 9, 2006, at 9:43 AM, Borut Bolčina wrote:

    If db row "points" to the same db row then it would be cyclic (for
    example - someone is his/her own manager), otherwise just
    reflexive. Is this correct?
    Ok, it is coming back to me... "multi-reflexive" simply means that
    there are multiple different relationships between the rows of the
    same table. So I wouldn't worry about single row pointing to self, as
    it doesn't violate constraints on insert, but say you have R1 and R2
    relationships within the same table (e.g. Category table;
    parentCategory and relatedCategory relationships). There is a chance
    that two or more rows will form a cycle: A -(parentCategory)-> B -
    (relatedCategory)-> A.

    Andrus

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedMay 20, '06 at 1:39a
activeOct 11, '06 at 1:11a
posts10
users5
websitecayenne.apache.org

People

Translate

site design / logo © 2021 Grokbase