Re: Getting complex queries in cayenne

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Fri May 06 2005 - 13:05:55 EDT

  • Next message: Bryan Lewis: "Re: Getting complex queries in cayenne"

    > 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



    This archive was generated by hypermail 2.0.0 : Fri May 06 2005 - 13:05:58 EDT