cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: newbie question
Date Tue, 22 Apr 2008 12:04:38 GMT
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 <andrus@objectstyle.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
>>


Mime
View raw message