String ejbql = "SELECT max(p.estimatedPrice) FROM Painting p";
Number n = (Number) DataObjectUtils.objectForQuery(context, new
EJBQLQuery(ejbql));
Andrus
On Apr 22, 2008, at 2:47 PM, Borut Bolčina wrote:
> Hello Andrus,
>
> what is the elegant 3.0M3 Cayenne way to do select MAX?
>
> Thanks,
> Borut
>
> 2007/10/9 Andrus Adamchik <andru..bjectstyle.org>:
>
>> Hi Jan,
>>
>> Looks like what you need is a SQLTemplate query:
>>
>> http://cayenne.apache.org/doc/sqltemplate-query.html
>>
>> Here is a mockup code example:
>>
>> SQLTemplate q = new SQLTemplate(SomeClass.class, "select MAX(id) from
>> table");
>> q.setFetchingDataRows(true);
>>
>> Map row = (Map) DataObjectUtils.objectForQuery(q);
>> Number id = (Number) row.values().iterator().next();
>>
>> (Cayenne 3.0 will be featuring more elegant API to achieve that,
>> but still
>> the code above should work just as well)
>>
>> Andrus
>>
This archive was generated by hypermail 2.0.0 : Tue Apr 22 2008 - 08:05:10 EDT