Re: Relationship caching

From: Laurent Marchal (lmarcha..maeur.com)
Date: Tue Apr 15 2008 - 13:03:24 EDT

  • Next message: Jeff Pierson: "EJBQL problem"

    It's a nice solution , i found another too that i missed in the
    documentation :

    RelationshipQuery is used by Cayenne internally to fetch object(s)
    related to a single given object via a mapped ObjRelationship. In some
    cases the query can be used directly in the application, e.g. if we want
    to refresh related objects.

    ObjectId id = new ObjectId("Artist", "ARTIST_ID", 55);
    RelationshipQuery query = new RelationshipQuery(id, "paintingArray", true);
    List paintings = context.performQuery(query);

    thanks.

    Mike Kienenberger wrote:
    > One way to guarantee it would be to change the code generation so that
    > the getters perform an explicit query. You'll always be sure to get
    > the latest database values, and you won't have to worry about
    > invalidating anything.
    >
    > In Cayenne 1.2 code, it'd look something like this, although there's a
    > bit more work involved in getting the generator to populate the
    > upper-case values. If you need help with that, ask.
    >
    > public List<AccessCode> getRelatedAccessCodes()
    > {
    > return getDataContext().performQuery(
    > new SelectQuery(RELATIONSHIP_TARGET_ENTITY_CLASS,
    >
    > ExpressionFactory.matchExp(REVERSE_RELATIONSHIP_PROPERTY_NAME,
    > this)));
    > }
    >
    > On 4/15/08, Laurent Marchal <lmarcha..maeur.com> wrote:
    >
    >> Hello,
    >>
    >> i have disabled caching in cayenne with :
    >>
    >> <property name="cayenne.DataDomain.sharedCache"
    >> value="false"/>
    >>
    >> but when i want to use a flatened relationship like :
    >>
    >> List<AccessCode> userAccessCodes = user.getRelatedAccessCodes();
    >>
    >> the SQL request is only made the first time, after cayenne use his cache to
    >> return the AccessCode list.
    >> The only way i found to force cayenne to resend the query is to use :
    >>
    >> _context.performNonSelectingQuery(new
    >> RefreshQuery(user));
    >>
    >> but this query invalidate all others relationships of the user object.
    >>
    >> - Why cayenne is caching, how can i disable all caches ?
    >> - Is there a way to NOT cache relationships by default and re-ask
    >> relationships each time ?
    >>
    >> thanks.
    >>
    >> Laurent Marchal
    >>
    >>
    >
    > _________________________________________________________________________
    >
    > Ce message a été vérifié par l'antivirus de MDaemon (md6).
    >
    > Par précaution, n'ouvrez pas de pièces jointes de correspondants inconnus.
    > _________________________________________________________________________
    >
    >
    > ___________________________________________________
    >
    > Ce message a été vérifié par l'antivirus de MDaemon 5 .
    >
    > Par précaution, n'ouvrez pas de pièces jointes de correspondants inconnus.
    > ___________________________________________________
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Tue Apr 15 2008 - 13:03:55 EDT