You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Borut Bolčina <bo...@gmail.com> on 2010/11/04 14:48:34 UTC

Re: Writable FKs

I'm back.

I created object attributes for 3 foreign keys. Example for one of them:

    public void setStreetId(Integer streetId) {
        writeProperty("streetId", streetId);
    }
    public Integer getStreetId() {
        return (Integer)readProperty("streetId");
    }

and now instead of setting the relationship:

    houseNumber.setStreet(localStreet);

I do:

    houseNumber.setStreetId(streetMid);

But now I am getting

Validation failure for com.acme.maps.model.HouseNumber.street: "street"  is
required.

Nowhere in the mapping file or in the modeler there is an option to set the
optionality of the relationship, only for attributes. Why am I getting this
validation message?

At the database level, the FK attribute is set to "NOT NULL", but this is
not related with the Cayenne.

Hints?

-Borut


2010/10/20 Andrus Adamchik <an...@objectstyle.org>

>
> On Oct 19, 2010, at 10:36 AM, Borut Bolčina wrote:
>
> > This way using
> >
> > street.setTown(localTown);
> >
> > does not set the relationship, it inserts NULL for town_id FK in the
> streets
> > table. Or did you mean something else?
>
>
> Probably (?) didn't quite get the explanation of your mapping. Anyways,
> have you tried setting meaningful FK, mapped as an ObjAttribute?
>
> Andrus
>
>

Re: Writable FKs

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Nov 4, 2010, at 9:48 AM, Borut Bolčina wrote:

> At the database level, the FK attribute is set to "NOT NULL", but this is
> not related with the Cayenne.

Yeah, this is what triggers the validation message. I'd say it is a bug - Cayenne should be smarter about meaningful FK + relationship validation. For now you can probably uncheck NOT NULL and file a Jira.

Andrus