Return-Path: X-Original-To: apmail-cayenne-user-archive@www.apache.org Delivered-To: apmail-cayenne-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0B56279E6 for ; Sun, 21 Aug 2011 08:18:43 +0000 (UTC) Received: (qmail 47257 invoked by uid 500); 21 Aug 2011 08:18:42 -0000 Delivered-To: apmail-cayenne-user-archive@cayenne.apache.org Received: (qmail 47056 invoked by uid 500); 21 Aug 2011 08:18:26 -0000 Mailing-List: contact user-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cayenne.apache.org Delivered-To: mailing list user@cayenne.apache.org Received: (qmail 47035 invoked by uid 99); 21 Aug 2011 08:18:18 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 21 Aug 2011 08:18:18 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [208.78.103.231] (HELO vorsha.objectstyle.org) (208.78.103.231) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 21 Aug 2011 08:18:13 +0000 Received: (qmail 7232 invoked from network); 21 Aug 2011 08:17:50 -0000 Received: from unknown (HELO ?127.0.0.1?) (127.0.0.1) by localhost with SMTP; 21 Aug 2011 08:17:50 -0000 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Apple Message framework v1084) Subject: Re: SQLTemplate query with MIN() group function From: Andrus Adamchik In-Reply-To: Date: Sun, 21 Aug 2011 11:17:49 +0300 Content-Transfer-Encoding: 7bit Message-Id: <4E19149B-709F-4CCE-BE9A-274C7E3C7F19@objectstyle.org> References: To: user@cayenne.apache.org X-Mailer: Apple Mail (2.1084) X-Virus-Checked: Checked by ClamAV on apache.org 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