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

From: Andrey Razumovsky (razumovsky.andre..mail.com)
Date: Tue Mar 17 2009 - 14:34:31 EDT

  • Next message: Mike Kienenberger: "Re: ClassCastException ...ToManyList cannot be cast to ...Persistent"

    Dan,

    As far as I know, Cayenne *should* allow that prefetch and there should be
    less than N+1 select. Is there any exception now? You'd likely want to check
    prefetch docs [1] to see that your query isn't under limitation described
    there.

    About flattened relationships, these ones only affect object layer, not
    database layer. So all DB structure will remain untouched. Have a look at
    many-to-many modeling article [2]! It's a bit out of date (ObjRelationship
    mapping dialog has changed recently and became more user-friendly), but
    you'll get the point!

    Andrey

    [1] http://cayenne.apache.org/doc/prefetching.html
    [2] http://cayenne.apache.org/doc/many-to-many-relationships.html

    2009/3/17 Dan <daniel.can..mail.com>

    > 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 - 14:35:06 EDT