Re: ClassCastException ...ToManyList cannot be cast to ...Persistent

From: Dan (daniel.can..mail.com)
Date: Tue Mar 17 2009 - 13:52:55 EDT

  • Next message: Andrey Razumovsky: "Re: ClassCastException ...ToManyList cannot be cast to ...Persistent"

    Andrey Razumovsky <razumovsky.andrey <at> gmail.com> writes:

    >
    > Hi Dan!
    >
    > It seems quite strange to me that relationship from PARTY_CASE_LINK to PARTY
    > is called "parties". So seems it's to-many. But PARTY_CASE_LINK has
    > "partyid", so no more than one PARTY can exist for PARTY_CASE_LINK.
    > Also can't flattened relationships [1] be useful for you in this case?
    >
    > [1] http://cayenne.apache.org/doc/flattened-relationships.html
    >
    > Andrey
    >

    Andrey,

    Ahh - yes - there was a flaw in the data model - the relationships to the
    PARTY_CASE_LINK table should be toMany, but all of the reverse relationships
    should be toOne.

    So i now have relationships that allow me to get

    List<PartyCaseLink> casesLinks = pty.getPartyCases();
    for (PartyCaseLink caseLink : casesLinks)
    {
         CourtCase cases = caseLink.getCase();
         ... do stuff
    }

    That is now resolved, and I can get "half" way to the objects that I want
    without additional DB queries using:

    selectQuery.addPrefetch("partyCases");

    BUT -- i see that cayenne is not allowing me to addPrefetch all the way to the
    "case" -- e.g. i want to:

    selectQuery.addPrefetch("partyCases.case");

    to avoid going back to the database N times (1 per row).

    ...

    Also - flattened relationships look interesting, but since I have a "real"
    relationship in the database there already, shouldn't i be able to use that?

    Thanks again in advance.

    dan



    This archive was generated by hypermail 2.0.0 : Tue Mar 17 2009 - 13:53:42 EDT