Generating primary key locally without extra tables

From: yvind Harboe (oyvind.harbo..ylin.com)
Date: Wed Jun 21 2006 - 02:18:08 EDT

  • Next message: Borut Bolčin: "MySql auto generated PK"

    Problem:

    I'm using Cayenne for projects where I can't modify the database
    schema on the server.

    These databases use server generated primary keys. MSAccess, MS SQL
    Server and Oracle.

    The number of new records created are very small(max 1/minute), so I'm
    rather insensitive to performance of record creation.

    Q: Does a strategy for generating keys locally exist?

    This strategy should work across databases where Cayenne does not
    support server generated primary keys.

    Getting a primary key by e.g.:

    SELECT MAX(ID)+1 FROM FOO

    This would a) be slow b) risk a collision when inserting.

    Qs:

    a) can I always override a server generated key?
    b) would it be sufficient to use exception handling and retry e.g. N times?

    -- 
    yvind Harboe
    http://www.zylin.com
    



    This archive was generated by hypermail 2.0.0 : Wed Jun 21 2006 - 02:18:35 EDT