Re: ClassCastException, Cayenne 2.0.4

From: Ian Boston (ie..fd.co.uk)
Date: Mon Sep 08 2008 - 06:03:09 EDT

  • Next message: Michael Shea: "SelectQuery.setFetchLimit() performance"

    Yes, that fixed it.

    I need to be precise about what objects are set in the setList
    methods as although it may work sometimes ie when the object is
    created, when its reloaded in a query it could already be in the
    cache and will hit the ClassCastException.

    Thank you for your help.
    Ian

    On 8 Sep 2008, at 10:30, Ian Boston wrote:

    > Now I think I know where the problem is, the type checking in the
    > setList is not precise enough, both (DbPersonAddress and DbAddress)
    > extend a CayenneDataObject and implement Address, so are treated
    > the same. I need to put some more precise checking on the elements
    > to ensure setList does the right thing.
    > Ian
    >
    >
    > On 8 Sep 2008, at 09:29, Andrus Adamchik wrote:
    >
    >>
    >> On Sep 8, 2008, at 11:18 AM, Ian Boston wrote:
    >>
    >>> Fantastic, thank you.
    >>>
    >>> One last question:
    >>> is this because Cayenne does introspection on the methods of the
    >>> Db entity class ?
    >>>
    >>> Since setAddresses is part of the Person API, (so I cant change
    >>> it) I assume that changing the name of the underlying attribute
    >>> will also fix this ?
    >>>
    >>> Ian
    >>
    >> Not sure I understand the question. So I maybe answering something
    >> you already know. What happens is that DbPerson.setAddresses(..)
    >> calls BaseCayenneShindigData.setList(..) method which in turn
    >> calls. 'Cayenne.DataObject.addToManyTarget("addresses", Address).
    >> 'addToManyTarget' is a generic method so it doesn't do any type
    >> checking, letting Address slip through where DbPersonAddress
    >> object is expected.
    >>
    >> So I guess when you are creating the test data, you need to create
    >> Address objects as well as DbPersonAddress objects explicitly and
    >> connect DbPersonAddress objects with DBPerson.
    >>
    >> Andrus
    >



    This archive was generated by hypermail 2.0.0 : Mon Sep 08 2008 - 06:04:06 EDT