newbie question - exception thrown getting PK for new object

From: chad smith (cksuta..otmail.com)
Date: Wed Oct 19 2005 - 07:24:22 EDT

  • Next message: Andrus Adamchik: "Re: newbie question - exception thrown getting PK for new object"

    here is a snapshot of my code ...
    -----------------------------------------
    public WebSite getBlankWebSite() throws DataAccessException {
            WebSite website = (WebSite)
            threadDataContext().createAndRegisterNewObject(WebSite.class);
            return website;
        }

        public boolean addWebsite(WebSite website) throws DataAccessException {
            if (website.getWebSiteId() == null {
                int id = DataObjectUtils.intPKForObject(website);
                website.setWebSiteId(new Integer(id));
            }
            website.getDataContext().commitChanges();
            return true;
        }
    -------------------------------------------
    I call the getBlankWebSite method, populate the object with form data, and
    then call addWebsite method. I get this error (stack trace)...

    org.objectstyle.cayenne.CayenneRuntimeException: [v.1.2M5 July 22 2005]
    Can't get primary key from temporary id.
            at
    org.objectstyle.cayenne.DataObjectUtils.extractObjectId(DataObjectUtils.java:154)
            at
    org.objectstyle.cayenne.DataObjectUtils.pkForObject(DataObjectUtils.java:110)
            at
    org.objectstyle.cayenne.DataObjectUtils.intPKForObject(DataObjectUtils.java:94)
            at cks.website.WebsiteDAOImpl.addWebsite(WebsiteDAOImpl.java:20)

    ... when calling this method ...

       int id = DataObjectUtils.intPKForObject(website);

    Note: "PK", "Mandatory" & "Generated" are all selected on the "Attributes"
    tab for the entity in the modeler

    thanks for any help

         Chad



    This archive was generated by hypermail 2.0.0 : Wed Oct 19 2005 - 07:24:26 EDT