Bryan,
Good catch, thanks! 'writeProperty' meaning should be limited to
simple properties (and also value holders such as collections or 1.2
org.objectstyle.cayenne.ValueHolder). 'setToOneTarget' should be used
for to-one. I will update the docs.
Andrus
On Apr 27, 2006, at 7:31 PM, Bryan Lewis wrote:
> 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 : Fri Apr 28 2006 - 09:41:01 EDT