cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: SQLTemplate query with MIN() group function
Date Sun, 21 Aug 2011 08:17:49 GMT
query.setFetchingDataRows(true); 

I suspect the above is needed here.

Andrus

On Aug 20, 2011, at 6:07 PM, Chris Murphy (www.strandz.org) wrote:

> I am trying to do this query through Cayenne:
> 
> select MIN( RD.sampleTime)
> from SamplePoint SP, GasPoint GP, Reading RD
> where RD.gasPoint_fk = GP.pk
> and GP.samplePoint_fk = SP.pk
> and SP.name = "54_CT_gas";
> 
> This is the code I am using:
> 
> String query =
>    //"select #result('MIN( RD.sampleTime)' 'java.util.Date')\n" +
>    "select MIN( RD.sampleTime)\n" +
>    "from samplePoint SP, gasPoint GP, Reading RD\n" +
>    "where RD.gasPoint_fk = GP.pk\n" +
>    "and GP.samplePoint_fk = SP.pk\n" +
>    "and SP.name = $nameParam";
> SQLTemplate rawSelect = new SQLTemplate( SamplePoint.class, query);
> rawSelect.setParameters( Collections.singletonMap( "nameParam",
> "\"54_CT_gas\""));
> DataContext context = (DataContext)dataStore.getEM().getActualEM();
> List result = context.performQuery( rawSelect);
> if(result.size() == 1)
> {
>    Object resultObj = result.get( 0);
>    Err.pr( "result: " + resultObj);
>    if(resultObj == null)
>    {
>        Err.pr( "One row returned but contains a null object");
>    }
>    else
>    {
>        Err.pr( "Result is of type " + resultObj.getClass().getName());
>    }
> }
> 
> The query works without any error, but this is what is output:
> 
> result: null
> One row returned but contains a null object
> 
> Can anyone point me in the right direction as to what I might be doing
> wrong?
> 
> thanks ~ Chris Murphy


Mime
View raw message