Re: Getting complex queries in cayenne

From: Dhruti Ramani (dhrutiraman..ahoo.com)
Date: Fri May 06 2005 - 14:17:39 EDT

  • Next message: Sami Mohammed: "Re: Getting complex queries in cayenne"

    I tried the second option and it works now.
     
    Thank you so much. I really like this user group.
    Denna

    Andrus Adamchik <andru..bjectstyle.org> wrote:

    > I understand those concepts now. thanks.
    >
    > I tried the way you have suggested but still returns null values. Even
    > if I am not using complex query just "select * from cahflow", it returns
    > all rows with null value.
    >
    > Any idea?
    > Denna

    Doing "select * ..." may not produce the result that Cayenne understands.
    The outcome is DB and configuration-dependent. I suggest describing each
    column in the result explicitly buy using the #result() directive (see
    docs on it at
    http://objectstyle.org/cayenne/userguide/fetch/sqltemplate-scripting.html).

    Or use data rows [query.setFetchingDataRows(true) or corresponding
    checkbox in the Modeler] - Cris mentioned this briefly. The result of your
    original aggregate query won't map to any of the entities anyway, so data
    rows approach seems more sensible.

    What this means is that the result will contain java.utl.Map instances
    instead of DataObjects. Then you can take each such map and convert it to
    your "aggregated" object:

    SQLTemplate query = ...
    query.setFetchingDataRows(true);
    List rows = context.performQuery(query);

    Iterator it = rows.iterator();
    while(it.hasNext()) {
    Map map = (Map) it.next();
    // do whatever...
    }

    Andrus

                    
    ---------------------------------
    Do you Yahoo!?
     Make Yahoo! your home page



    This archive was generated by hypermail 2.0.0 : Fri May 06 2005 - 14:17:42 EDT