FAQ
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

Search Discussions

  • Andrus Adamchik at Sep 21, 2009 at 6:21 am

    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
  • Andreas Hartmann at Sep 23, 2009 at 1:37 pm
    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedSep 20, '09 at 9:50p
activeSep 23, '09 at 1:37p
posts3
users2
websitecayenne.apache.org

People

Translate

site design / logo © 2021 Grokbase