Re: primary key increment for MySQL

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Mon Jan 06 2003 - 17:18:30 EST

  • Next message: Dave Paules: "propogating (or posting events of) object changes"

    Hi Dave,

    First, I wanted to point out the reason why increment is set to 20. This is
    to inhance PK generation performance. Basically an application will cache 20
    keys instead of one. When you are doing many inserts this will require a
    single trip to the database for the primary key for every 20 rows inserted.
    If you set it to 1, it will require one trip per row.

    If you still feel a need to change that, here is an example (requires some
    going down to Cayenne access layer):

    // Do this on app startup...

    // Assume there is a persistent class called "Employee",
    // any other will do too..
    DataDomain domain = Configuration.getSharedConfig().getDomain();
    ObjEntity ent = domain.getEntityResolver().getObjEntity(Employee.class);
    DbAdapter adapter = domain.dataNodeForObjEntity(ent).getAdapter();

    ((JdbcPkGenerator)adapter.getPkGenerator()).setPkCacheSize(1);

    This should work.

    Andrus

     

     

    Dave Paules writes:

    > Hi list,
    > Does anyone know how to change the increment for the primary key.
    > I am using the auto_pk_support table with Cayenne. New objects receive a pk
    > value that is incremented by 20 since the last new object. I'd like to set
    > the pk increment to 1, not 20.
    >
    > Thanks
    > Dave Paules
    > Quantum Leap
    > www.quantumleap.us
     



    This archive was generated by hypermail 2.0.0 : Mon Jan 06 2003 - 17:18:34 EST