Re: AUTO_INCREMENT pk generation in MySQL

From: Andrus Adamchik (
Date: Thu Sep 30 2004 - 12:33:44 EDT

  • Next message: Andrus Adamchik: "Re: Multiple Object Models"

    Hi Robert,

    Customizing adapter for this case makes sense and is actually the way
    to solve you problem. As you may have seen from Cayenne API and
    sources, DbAdapter internally uses a PkGenerator for primary key
    operations. MySQL implementations are "MySQLPkGenerator" and
    "MySQLAdapter". You can subclass them following one of these scenarios:

    1. Create a full custom adapter:
    Subclass both MySQLPkGenerator and MySQLAdapter. See the instructions
    If you create such adapter, it can be used in the modeler and will
    behave as any other Cayenne adapter in all respects.

    2. Customize PkGenerator in the code:
    Just subclass MySQLPkGenerator. You can keep using MySQLAdapter, but
    somewhere on app startup you will have to set a custom pk generator in
    the code (dataNode.getAdapter().setPkGenerator(mySubclassInstance)).
    This is less work than (1) but is more cludgy.


    On Sep 30, 2004, at 8:56 AM, Robert Bundy wrote:

    > We have an existing database that uses AUTO_INCREMENT to create the
    > primary keys for several tables.  This presents a problem for a
    > Cayenne-based application since we will have legacy applications
    > interacting with the database at the same time.  Someone has suggested
    > that it might be possible to subclass the DbAdapter class to get the
    > behavior that we need.  Does this seem possible?  Does it make sense? 
    > Thanks.
    > --
    > Robert Bundy
    > Zenodata Corporation
    > (303) 604-9884 x142
    > cell: (720) 339-1397

    This archive was generated by hypermail 2.0.0 : Thu Sep 30 2004 - 12:33:49 EDT