writeProperty() no longer useful for relationships

From: Bryan Lewis (brya..aine.rr.com)
Date: Thu Apr 27 2006 - 19:31:45 EDT

  • Next message: Jürgen Saar: "Re: How to enforce Delete before Insert?"

    Another little surprise we encountered with 1.2B2... dunno if it's a bug
    or only a documentation correction or neither. I had some code that
    used CayenneDataObject.writeProperty() to write a new object's
    attributes and to-one relationships. It made it easy to copy the values
    from a Map with keys named the same as the properties.

    This worked fine until now, and the javadocs say "This method can safely
    be used instead of or in addition to the auto-generated property
    modifiers in subclasses of CayenneDataObject." But now if I set a
    *relationship* with writeProperty() , the foreign key is left null in
    the generated SQL.

        Before commit, object = {<ObjectId:WebSlowpay, TEMP:...>; new
        [companyContact=>{<ObjectId:CompanyContact, CONTACT_NIC_ID=109572>}
        ... That's a to-one relationship on the key Contact_Nic_ID. Rest of
    properties omitted...

        The SQL is:

        INSERT INTO WEBSLOWPAY (CONTACT_NIC_ID, ...) VALUES (?, ...)
        [batch bind: NULL, ...] -- should be 109572
        *** error. java.sql.SQLException: ORA-01400: cannot insert NULL ...

    It works fine if I change it to use the normal setter method
    setCompanyContact() or the equivalent setToOneTarget().



    This archive was generated by hypermail 2.0.0 : Thu Apr 27 2006 - 19:32:18 EDT