You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Dave Merrin <dm...@ipasystems.co.uk> on 2006/04/10 12:02:42 UTC

Object Creation and Settings Ids

Hi,

Given a new object I'd like to be able to set on of the properties (a 'to'
property) without having the other object(only the ID). e.g.

Item is the object I'm creating. It has a property called ItemType which is
another object. I have the ItemType ID but not the actual object. I'd like
to have a method called Item.setItemTypeID(Long itemTypeId).

Is this possible?

Cheers,

Dave


RE: Object Creation and Settings Ids

Posted by Dave Merrin <dm...@ipasystems.co.uk>.
Hi Andrus,

thanks for that. I think I'd tried it before but ran into validation
problems (I had a setToItemType() method and the db field is required).
Since then I've looked through and overridden the validateForSave method
(can't remember why). I should be able to modify this method to allow for
direct and indirect access.

Cheers,

Dave

> -----Original Message-----
> From: Andrus Adamchik [mailto:andrus@objectstyle.org]
> Sent: 10 April 2006 12:50
> To: cayenne-user@incubator.apache.org
> Subject: Re: Object Creation and Settings Ids
>
>
> Technically this can be done by mapping a foreign key column as an
> ObjAttribute. Still it would go against the spirit of Cayenne. I
> suggest to use a real ItemType object. DataObjectUtils.objectForPk
> (..) should be a pretty efficient way to get a hold of ItemType
> instance, as after the object is fetched for the first time, it will
> be served from shared cache on subsequent calls.
>
> Andrus
>
>
>
> On Apr 10, 2006, at 2:02 PM, Dave Merrin wrote:
> > Hi,
> >
> > Given a new object I'd like to be able to set on of the properties
> > (a 'to'
> > property) without having the other object(only the ID). e.g.
> >
> > Item is the object I'm creating. It has a property called ItemType
> > which is
> > another object. I have the ItemType ID but not the actual object.
> > I'd like
> > to have a method called Item.setItemTypeID(Long itemTypeId).
> >
> > Is this possible?
> >
> > Cheers,
> >
> > Dave
>


Re: Object Creation and Settings Ids

Posted by Andrus Adamchik <an...@objectstyle.org>.
Technically this can be done by mapping a foreign key column as an  
ObjAttribute. Still it would go against the spirit of Cayenne. I  
suggest to use a real ItemType object. DataObjectUtils.objectForPk 
(..) should be a pretty efficient way to get a hold of ItemType  
instance, as after the object is fetched for the first time, it will  
be served from shared cache on subsequent calls.

Andrus



On Apr 10, 2006, at 2:02 PM, Dave Merrin wrote:
> Hi,
>
> Given a new object I'd like to be able to set on of the properties  
> (a 'to'
> property) without having the other object(only the ID). e.g.
>
> Item is the object I'm creating. It has a property called ItemType  
> which is
> another object. I have the ItemType ID but not the actual object.  
> I'd like
> to have a method called Item.setItemTypeID(Long itemTypeId).
>
> Is this possible?
>
> Cheers,
>
> Dave