Re: transaction ordering

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Jul 08 2004 - 22:54:24 EDT

  • Next message: Bryan Lewis: "Re: Cayenne in a framework -> Value Objects"

    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 : Thu Jul 08 2004 - 22:54:28 EDT