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