Re: postgres PK serial column insert error

From: Jürgen Saar (jsaa..eb.de)
Date: Tue Aug 03 2004 - 02:37:05 EDT

  • Next message: Jürgen Saar: "mandatory reverse relation"

    First there is a method in CayenneDataObject:
        validateForInsert: Here you can add the PK

    If you want the database to generate the primary key
    this is not really a good idea, because you might lose
    the the free choice of the databaseysystem you want to use.
    This is one of the key features of a framework like cayenne.
    For my point of view, it might have a little less performance
    but I like this kind of independence.

    --- Juergen ---

    <geller..arkwing.uoregon.edu> schrieb am 02.08.04 21:10:33:
    >
    > Hi,
    > I'm using postgres 7.3.3 as my backend. My goal is to add a new record to
    > the database. I've already got a context, and can select records just fine.
    > When I try to commit the add it errors out when trying to get the next value
    > for loginid, the pk.
    >
    > javax.servlet.ServletException: [v.1.1B2 July 25 2004] Commit Exception
    >
    > Caused by: java.sql.SQLException: ERROR: Relation "auto_pk_support" does
    > not exist
    >
    >
    > I would like to do something along the lines of making an INSERT statement
    > like: "INSERT INTO login (username, password) VALUES ('test', 'abc');"
    >
    > Instead, it looks like Cayenne is accessing 'auto_pk_support' for the next
    > login id. This is two trips to the db, instead of one.
    >
    >
    > My code:
    > Login newLogin = (Login) context.createAndRegisterNewObject(Login.class);
    > newLogin.setUsername("test");
    > newLogin.setPassword("abc");
    > context.commitChanges();
    >
    >
    > Table:
    > CREATE TABLE public.Login (
    > LoginID SERIAL NOT NULL
    > , Username VARCHAR(30)
    > , Password VARCHAR(30)
    > , PRIMARY KEY (LoginID)
    > );
    >
    > Please help! Thanks!
    >
    > Laurence Gellert
    >
    >
    >

    ____________________________________________________
    Aufnehmen, abschicken, nah sein - So einfach ist
    WEB.DE Video-Mail: http://freemail.web.de/?mc=021200



    This archive was generated by hypermail 2.0.0 : Tue Aug 03 2004 - 02:37:14 EDT