Re: postgres serial

From: Koen Segers (KoenSeger..carlet.be)
Date: Mon Feb 14 2005 - 19:00:32 EST

  • Next message: Andrus Adamchik: "Re: postgres serial"

    On Monday 14 February 2005 00:58, Andrus Adamchik wrote:
    > > newcourse.setID(/*whatnumber*/);
    >
    > You don't need this line - Cayenne will generate PK for you. Unless you
    > have a really good reason to do that, I will go further and recommend
    > to remove ID attribute from Java class and let Cayenne handle it all
    > the way. If you need to read generated ID, use DataObjectUtils -
    > http://objectstyle.org/cayenne/api/cayenne/org/objectstyle/cayenne/
    > DataObjectUtils.html

    I read this page over and over but still it doesn't work.
    What I have done allready:
    Generate Database Schema -> Create Primary key support for all classes
    added this to source:
    Users user = (Users) context.createAndRegisterNewObject(Users.class);
    DataObjectUtils.intPKForObject(user);
    user.setName(getUserName());
    user.setPassword(getPassword());
    user.setAuthlevel(getAuthLevelID());
    context.commitChanges();
    retrieved error:
    Unable to invoke method createUser on website.CreateUse..e22632[CreateUser]:
    [v.1.1 December 6 2004] Can't get primary key from temporary id.
    Stack Trace:
    org.objectstyle.cayenne.DataObjectUtils.extractObjectId(DataObjectUtils.java:139)
    org.objectstyle.cayenne.DataObjectUtils.pkForObject(DataObjectUtils.java:110)
    org.objectstyle.cayenne.DataObjectUtils.intPKForObject(DataObjectUtils.java:94)
    website.CreateUser.createUser(CreateUser.java:83)
    >
    > Andrus

    Thx for reply !

    >
    > On Feb 13, 2005, at 10:13 AM, Koen Segers wrote:
    > > Hi,
    > >
    > > I used phpPgAdmin to create my database. I used a serial type to
    > > increment the
    > > id automaticly. It creates automaticly a sequence.
    > >
    > > Now I want to insert a field with cayenne. How can request the id?
    > > Course newcourse = (Course)
    > > context.createAndRegisterNewObject(Course.class);
    > > newcourse.setID(/*whatnumber*/);
    > >
    > > Greetz
    > > --
    > >
    > > Koen Segers
    > >
    > > <koenseger..carlet.be>
    > > <http://eddyvite.dyndns.org>

    -- 
    

    Koen Segers

    <koenseger..carlet.be> <http://eddyvite.dyndns.org>



    This archive was generated by hypermail 2.0.0 : Mon Feb 14 2005 - 19:00:46 EST