Re: Using SQL ABS

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Mon Jul 26 2010 - 08:50:41 UTC

  • Next message: masjab: "Re: cayenne.xml not found"

    Unfortunately neither SelectQuery nor EJBQLQuery support functions in
    the ORDER BY clause (something we should probably address in 3.1). You
    have a few choices:

    * Use SQLTemplate

    * Map an extra attribute in RiscoTotal DbEntity as "ABS(VARIACAO)",
    then an attribute in ObjEntity connected to "ABS(VARIACAO)"
    DbAttribute. Then you can order on this fake attribute. (I know you
    can map this, but I haven't tried running queries with such mapping. I
    guess that should work).

    Andrus

    On Jul 25, 2010, at 1:19 AM, Andre Lomonaco wrote:

    > Hi Everyone,
    >
    > I'm newbie in Cayenne and I will apreciate if someone can help
    > me in one question..
    >
    > I have a table with a VARIACAO Field (Type DOUBLE)
    > I can store in this Field Positive and Negative Numbers
    >
    > When I execute the following code, it's return to me first the
    > Negative values and after the Positive values
    >
    > SelectQuery query = new SelectQuery(RiscoTotal.class);
    > query.addOrdering(RiscoTotal.VARIACAO_PROPERTY,true);
    >
    > ObjectContext context = BaseContext.getThreadObjectContext();
    > List<RiscoTotal> riscoTotal = context.performQuery(query);
    >
    > Return: -12.0, -6.0, 3.0, 15.0
    >
    > My questions is:
    >
    > How can I do to make a query to return only the ABS value
    > I wanna receive the following results
    >
    > 15.0, -12.0, -6.0, -3.0
    >
    > My Best Regards,
    >
    > Andre Lomonaco



    This archive was generated by hypermail 2.0.0 : Mon Jul 26 2010 - 08:51:16 UTC