Re: Query-Question

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Tue Jan 28 2003 - 13:32:40 EST

  • Next message: David Solis: "FW: Cayenne and Hibernate"

    Michael,

    when your SelectQuery root is artist, you are fecthing Artists, not
    paintings. So basically the second part of the qualifier tells "Don't
    include *artists* that have ALL their paintings set to Off", and not
    "Don't include paintings that are off".

    Paintings are obtained later via a relationship and relationship is not
    affected by the earlier query, it is rather a property of an Artist
    object. This is how relationships work by design.

    So how to fetch the "off" paintings? You can do it 2 step:

    1. Fetch all artists matching the name.
    2. For each artist object (or for all of them at once if this is what you
    need) execute a query on Painting with qualifier like:

    Artist artist; // assume this exists
    Expression exp = ExpressionFactory.matchExp("toArtist", artist);
    exp = exp.andExp(ExpressionFactory.matchExp("status", "off");

    or alternatively

    List artists;
    Expression exp = ExpressionFactory.binaryPathExp(Expression.IN,
    "toArtist", artists);
    exp = exp.andExp(ExpressionFactory.matchExp("status", "off");

    Andrus

    > Hi,
    >
    > following situation:
    >
    > I've got several artists and each artists has several paintings. There
    > is a 1:n relationship from artist to painting. Just like in the
    > cayenne-example.
    >
    > Now I want to get a special artist and for this artist only those
    > paintings, where the status is off.
    >
    > I tried this by using the following code:
    >
    > ...
    > Expression qual = ExpressionFactory.binaryPathExp (Expression.EQUAL_TO,
    > "artistName",
    > strArtistNameName);
    >
    > qual = qual.andExp (ExpressionFactory.binaryPathExp(Expression.EQUAL_TO,
    > "hasPaintings.status",
    > "off"));
    > ...
    >
    >
    > After executing the query I'm getting a List of Artists (in this case
    > only one!). Using this one artist I'd like to get the paintings with the
    > status 'off'. By iterating through the list got from getHasPaintings I
    > see all paintings belonging to this artist. The status was ignored.
    >
    > I used the generated sql-query in MySql-Front and voila: I'm getting
    > only those paintings with the status 'off'. But within cayenne the
    > status will be ignored!
    >
    > Any help or suggestions?
    >
    > Michael



    This archive was generated by hypermail 2.0.0 : Tue Jan 28 2003 - 13:32:41 EST