Re: postgres serial

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

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

    On Tuesday 15 February 2005 01:15, Andrus Adamchik wrote:
    > You can't do this:
    > > DataObjectUtils.intPKForObject(user);
    >
    > until you do this:
    > > context.commitChanges();
    >
    > In fact, looking at your code, you don't need
    > "DataObjectUtils.intPKForObject(user)" line at all - it doesn't
    > accomplish anything, and without it everything else should just work.

    public void createUser(DataContext context){
      Users user = (Users) context.createAndRegisterNewObject(Users.class);
      //DataObjectUtils.intPKForObject(user);
      user.setName(getUserName());
      user.setPassword(getPassword());
      user.setAuthlevel(getAuthLevelID());
      context.commitChanges();
     }

    gives:
    unlabeledMessage: Validation has failed.
    validationResult: Validation failure for databaseExt.Users.id: "id" is
    required.
    Stack Trace:
    Validation failure for databaseExt.Users.id: "id" is required.
    org.objectstyle.cayenne.access.ObjectStore.validateUncommittedObjects(ObjectStore.java:950)
    org.objectstyle.cayenne.access.DataContext.commitChanges(DataContext.java:1260)
    org.objectstyle.cayenne.access.DataContext.commitChanges(DataContext.java:1236)
    website.CreateUser.createUser(CreateUser.java:87)

    So there is still a problem with the PK...

    > Cayenne generates PK automatically behind the scenes when you do
    > commitChanges. You don't need to help it in any way. "intPkForObject"
    > is intended to read and id once it is generated

    The generation is the problem.
    INSERT INTO users(name,password,authlevel) VALUES ('"+getUserName()+"',
    '"+getPassword()+"',"+getAuthLevelID()+")"
    Did work, but i prefer the oo style.

    > , so it is likely not
    > applicable in your case.
    >
    > Andrus
    >
    > On Feb 14, 2005, at 7:00 PM, Koen Segers wrote:
    > > 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.jav
    > > a:110)
    > > •
    > > org.objectstyle.cayenne.DataObjectUtils.intPKForObject(DataObjectUtils.
    > > java:94)
    > > • website.CreateUser.createUser(CreateUser.java:83)

    -- 
    

    Koen Segers

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



    This archive was generated by hypermail 2.0.0 : Mon Feb 14 2005 - 19:28:21 EST