RE: transaction ordering

From: Newton, Greg P. (gpnewto..-TEL.com)
Date: Fri Jul 09 2004 - 16:52:07 EDT

  • Next message: Andrus Adamchik: "Re: transaction ordering"

    Hi Andrus,

    I tried your suggestion, but no luck. I configured the adapter to support
    FK constraints, and I verify right before doing an operation that the JDBC
    adapter says "true" when I ask it supportsFkConstraints(). Unfortunately,
    the dependent rows are still being written first and I'm still getting the
    FK constraint violation from MySQL.

    Is there anything in the mapping that I should be looking for or verifying?
    I read about the "To Dep PK" attribute of DB relationships, but that didn't
    really seem to apply as the FK from the master table is not the primary key
    of the dependent table.

    Greg

    -----Original Message-----
    From: Andrus Adamchik [mailto:andru..bjectstyle.org]
    Sent: Thursday, July 08, 2004 10:54 PM
    To: cayenne-use..bjectstyle.org
    Subject: Re: transaction ordering

    Hi Greg,

    Ok, the issue here is preconfigured DbAdapter settings. Cayenne orders
    inserts/updates/deletes correctly, however if DbAdapter tells it that
    FK constraints are not supported by the target DB, ordering operation
    is skipped. MySQL adapter was written with MySQL 3.* in mind, so it
    assumes that FK constraints are absent.

    In the future we should probably make this configurable via the
    Modeler, but for now you can use these few lines of code on the app
    startup:

    DataDomain domain = Configuration.getSharedConfiguration().getDomain();
    DataNode node = domain.getNode("node_name_from_the_project");
    JdbcAdapter adapter = (JdbcAdapter) node.getAdapter();
    adapter.setSupportsFkConstraints(true);

    // this line is a bit kludgy,
    // what it does is forcing the node to rebuild its operation sorter
    node.setAdapter(adapter);

    Hope this helps.

    Andrus

    On Jul 8, 2004, at 10:17 PM, Newton, Greg P. wrote:
    > Hi,
    >
    > I'm using Cayenne to persist an object graph across 2 tables (Org,
    > Member).  The Org table has a 1-many relationship with Member.  The
    > member table has a FK relationship (parentId) back to the Org table.
    >
    >  
    >
    > When I'm doing the initial insert, I first create the Cayenne object
    > representing Org.  I then iterate through and create all of the Member
    > objects, adding each to the Member array on the Org object, and
    > setting the Member.parentId to be the primary key of the Org object.
    >
    >  
    >
    > Once everything is created, I then commit the changes.  
    >
    >  
    >
    > The problem I'm running into is a violation of the FK constraint setup
    > on the Member table (back to the primary key of Org).  When I looked
    > at the Cayenne logs, what I noticed is that the inserts for the Member
    > table are happening before the insert for the Org table.
    >
    >  
    >
    > I'm going to see if I can find a way to defer the constraint
    > evaluation to transaction commit on MySQL (I've done this for Oracle
    > before), but what I'm wondering is if there is any way to influence
    > the order of the inserts.  I'd prefer to have the Org row inserted
    > first, followed by all the Member rows.
    >
    >  
    >
    > Thanks!
    >
    > Greg
    >
    >  
    >
    >  
    >
    > <image.tiff> 
    >
    >  
    >
    >  
    >
    > Greg Newton
    > Chief Architect, Enhanced Services
    >
    > Z-Tel Communications, Inc.
    > 3340 Peachtree Rd. NE
    > Suite 2000
    > Atlanta, GA 30326
    >
    > gpnewto..-TEL.com
    >
    > tel:
    >
    > 404-504-0928
    >
    >
    >
    >  
    >
    >
    >  
    >
    >  
    >
    >  



    This archive was generated by hypermail 2.0.0 : Fri Jul 09 2004 - 16:51:07 EDT