Re: How to do GROUP BY dynamically?

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Fri Jan 07 2005 - 09:25:38 EST

  • Next message: Andrus Adamchik: "Re: Cayenne managed transactions vs. Container Managed"

    Hi Andreas,

    Adding GROUP BY would change object "identity", as you group multiple DB
    rows into one result row. So strictly speaking the returned result won't
    be a Artjoina instance anymore and using SelectQuery won't work.

    Instead I suggest using SQLTemplate and fetch data rows. If you don't want
    to create such query in the Modeler, you can do it in the code just as
    easy.

    Andrus

    > Hi,
    >
    > currently, I am doing this
    >
    > Expression qual = Expression.fromString(Artjoina.FORFATTARE_PROPERTY +
    > " <> ''");
    > SelectQuery proto = new SelectQuery(Artjoina.class, qual);
    > Map params = new HashMap();
    > SelectQuery query = proto.queryWithParameters(params);
    > return query;
    >
    > to get all FORFATTARE_PROPERTY out of Artjoina (which contains several
    > fields). Now I want to only return unique entries but using setDistinct
    > won't work because it only returns distinct rows (which will not be
    > distinct if all fields are considered).
    >
    > I also want to change the code so it dynamically choose the field and
    > optionally groups by it or not.
    >
    > Basically I need
    >
    > SELECT field_name FROM db GROUP BY field_name
    >
    > where field_name is dynamic. How would I do this? I can't and don't
    > want to
    > do this in the modeler.
    >
    > Regards,
    > Andreas Pardeike



    This archive was generated by hypermail 2.0.0 : Fri Jan 07 2005 - 09:25:40 EST