You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Andreas Hartmann <an...@apache.org> on 2009/09/20 23:49:46 UTC
Obtain relationship target objects of a DataObject
Hi everyone,
I'd like to write some generic code to replace the set of related
objects of a DataObject with a different set of objects. But I can't
figure out how to get the list of the target objects.
Here's some naiive code to illustrate what I'd like to achieve:
final List<DataObject> oldObjects = (List<DataObject>)
object.readProperty(name);
for (final DataObject targetObj : oldObjects) {
object.removeToManyTarget(name, targetObj, true);
}
for (final DataObject targetObj : newObjects) {
object.addToManyTarget(name, targetObj, true);
}
But apparently object.readProperty(…) doesn't return a list of the
existing target objects.
What would be the correct way to do this?
Thanks a lot in advance!
-- Andreas
--
Andreas Hartmann, CTO
BeCompany GmbH
http://www.becompany.ch
Tel.: +41 (0) 43 818 57 01
Re: Obtain relationship target objects of a DataObject
Posted by Andreas Hartmann <an...@apache.org>.
Hi Andrus,
thanks for your reply!
Andrus Adamchik schrieb:
> On Sep 21, 2009, at 12:49 AM, Andreas Hartmann wrote:
>
>> But apparently object.readProperty(…) doesn't return a list of the
>> existing target objects.
>
> It does and the code looks correct to me. Doublecheck that "name"
> corresponds to a property mapped as to-many relationship.
Apparently it was a concurrent list access issue. If I wrap the list in
a new array list before iterating, it works:
final List<DataObject> oldObjects
= new ArrayList<DataObject>((List<DataObject>)
object.readProperty(name));
So it's not a Cayenne issue; sorry for the noise.
-- Andreas
--
Andreas Hartmann, CTO
BeCompany GmbH
http://www.becompany.ch
Tel.: +41 (0) 43 818 57 01
Re: Obtain relationship target objects of a DataObject
Posted by Andrus Adamchik <an...@objectstyle.org>.
On Sep 21, 2009, at 12:49 AM, Andreas Hartmann wrote:
> But apparently object.readProperty(…) doesn't return a list of the
> existing target objects.
It does and the code looks correct to me. Doublecheck that "name"
corresponds to a property mapped as to-many relationship.
Andrus