Re: Validation failures with Primary Key

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Mon May 16 2005 - 09:37:06 EDT

  • Next message: Gentry, Michael \(Contractor\): "RE: OT: MySQL on Mac OS 10.4"

    I guess we need to update the Wiki entry... The phrase "To make a primary
    key available in a Java class, it must be mapped from the DbEntity to the
    ObjEntity, which is simple to do" is only related to a settable PK. If you
    follow these approach you must provide a value yourself.

    In case when you need read-only access to PK, but want Cayenne to take
    care of the initial value generation, do not create an ObjAttribute for
    PK. Instead create a simple cover method in the DataObject that reads PK
    via DataObjectUtils.

    Andrus

    > Maybe this is what's happening... If you're exposing the primary key as
    > an object attribute, you're taking the responsibility for setting it
    > when a new object is created. "Cayenne will not attempt to generate a
    > primary key on INSERT unless the field is empty, therefore you can
    > explicitly set a primary key value." If you do not set a value, you
    > will get the "id is required" error message.
    >
    >
    > ----- Original Message -----
    > From: "Doychi" <doychi-list..oychi-dina.ath.cx>
    > To: <cayenne-use..bjectstyle.org>
    > Sent: Monday, May 16, 2005 5:42 AM
    > Subject: Validation failures with Primary Key
    >
    >
    >> Hi all,
    >>
    >> I'm currently working on a project that is exposing the primary key of
    >> a Product using the instructions from the wiki
    > (http://objectstyle.org/confluence/display/CAY/Mapping+Primary+Keys). I
    > keep getting this message when attempting to create a new product.
    >>
    >>
    >> Validation failure for au.com.relevance.corporatedb.Product.id: "id"
    >> is required.
    >>
    >>
    >> I have tried both creating the object and then registering it and
    >> having the context create and register the object. The result is the
    >> same.
    >>
    >> Is there something I'm missing.
    >>
    >> --
    >> Doychi
    >> spdoychia..oychi-dina.ath.cx



    This archive was generated by hypermail 2.0.0 : Mon May 16 2005 - 09:37:08 EDT