Re: PK problem with Postgre

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Fri Apr 21 2006 - 02:26:06 EDT

  • Next message: Andrus Adamchik: "Re: Can not recognize the object passed in for the toOne relationship?"

    On Apr 21, 2006, at 4:42 AM, lsteel..inet.net.au wrote:
    >
    > When I was looking at the SQL statements Cayenne was using, it was
    > constantly
    > trying to include the id - thus causing problems with Postgres's
    > autoincrement.
    >
    > They seemed to think that Cayenne should just insert the record
    > and let
    > postgres worry about doing the autoincrement.

    This thread seems to be about two separate things - (1)
    autoincremented column values and (2) sequences used by Cayenne to
    generate PK. These are two different strategies (as mentioned in one
    of the messages that you quoted). Cayenne most certainly works with
    the second scenario (I am constantly using postgres myself)...

    > In postgres, if you want autoincrement you set the sequences up
    > and then you
    > just insert a record without trying to predict what the next id
    > will be.
    > Postgres should look after this.

    Regarding the first scenario - can you elaborate how you setup your
    tables? One way that I know is this:

    create sequence foo_bar_seq;
    create table foo (bar integer unique not null default nextval
    ('foo_bar_seq'));

    (Or is this something else?) The example above does not work with
    Cayenne because Postgres driver as of 8.0 does not implement
    Statement.getGeneratedKeys() thus making it impossible (ok, rather
    very hard) for Cayenne to retrieve the key generated in such way. The
    solution - do not tie a PK column to a sequence in Postgres, let
    Cayenne generate the key.

    I guess we may implement an equivalent of 'Statement.getGeneratedKeys
    ()' on Cayenne end by using Postgres proprietary API to retrieve
    generated keys (and thus enable scenario (1)), still I hoped the
    driver would provide that.

    Andrus



    This archive was generated by hypermail 2.0.0 : Fri Apr 21 2006 - 02:26:32 EDT