Return-Path: X-Original-To: apmail-openjpa-users-archive@minotaur.apache.org Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2071E1896E for ; Thu, 23 Apr 2015 10:33:14 +0000 (UTC) Received: (qmail 23512 invoked by uid 500); 23 Apr 2015 10:33:14 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 23470 invoked by uid 500); 23 Apr 2015 10:33:14 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 23458 invoked by uid 99); 23 Apr 2015 10:33:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Apr 2015 10:33:13 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: message received from 54.191.145.13 which is an MX secondary for users@openjpa.apache.org) Received: from [54.191.145.13] (HELO mx1-us-west.apache.org) (54.191.145.13) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Apr 2015 10:33:06 +0000 Received: from lb2-smtp-cloud2.xs4all.net (lb2-smtp-cloud2.xs4all.net [194.109.24.25]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTPS id A1E4D24C08 for ; Thu, 23 Apr 2015 10:32:45 +0000 (UTC) Received: from remote.huizemolenaar.nl ([213.125.4.82]) by smtp-cloud2.xs4all.net with ESMTP id KNYc1q00D1mAVTp01NYdGK; Thu, 23 Apr 2015 12:32:37 +0200 Received: from HMS11.hm.local ([fe80::6319:ce09:a29f:edfb]) by HMS11.hm.local ([fe80::6319:ce09:a29f:edfb%10]) with mapi id 14.03.0224.002; Thu, 23 Apr 2015 12:32:36 +0200 From: Henno Vermeulen To: "users@openjpa.apache.org" Subject: RE: criteria API generates a parameter for literal in group by but does not provide the value Thread-Topic: criteria API generates a parameter for literal in group by but does not provide the value Thread-Index: AdB9qPU9Gs3qPgB/Q2GliVCdp7iTPQAB5BKw Date: Thu, 23 Apr 2015 10:32:34 +0000 Message-ID: <2FFAFD73C8FCEA4FB07C5E997664B1A039CE10CA@HMS11.hm.local> References: <2FFAFD73C8FCEA4FB07C5E997664B1A039CE10AD@HMS11.hm.local> In-Reply-To: <2FFAFD73C8FCEA4FB07C5E997664B1A039CE10AD@HMS11.hm.local> Accept-Language: nl-NL, en-US Content-Language: nl-NL X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [192.168.123.123] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Virus-Checked: Checked by ClamAV on apache.org One addition (my question is still open). I can confirm that a valid workaround for this problem is to use setHint("o= penjpa.hint.UseLiteralInSQL", "true") and updating to OpenJPA 2.4.0 which i= s available in Maven central since a few days. Henno -----Oorspronkelijk bericht----- Van: Henno Vermeulen [mailto:henno@huizemolenaar.nl]=20 Verzonden: donderdag 23 april 2015 11:49 Aan: users@openjpa.apache.org Onderwerp: criteria API generates a parameter for literal in group by but d= oes not provide the value Hello, I have a query created using the criteria API where I group by an expressio= n that contains a small calculation using literal values. OpenJPA generates the correct SQL but does not provide the value of the gen= erated parameter in the group by clause. The query fails with a SQL excepti= on "The value is not set for the parameter number 9.". I can reproduce the issue with a minimal example. Suppose we have a person = class with integer age and length columns and we wish to select the average= length grouped by the person's age / 10: CriteriaBuilder cb =3D em.getCriteriaBuilder(); CriteriaQuery query =3D cb.createQuery(Doub= le.class); Root person =3D query.from(Person.class); Expression averageLength =3D cb.avg(person.= get("length")); CriteriaQuery select =3D query.select(avera= geLength); select.groupBy(cb.quot(person. get("age"),= cb.literal(10))); // optional where, useful to ensure parameters are = logged select.where(cb.gt(person. get("age"), cb.= literal(20))); System.out.println("result: " + em.createQuery(quer= y).getResultList()); Whe running this query with trace and displaying parameters on I get: 1067 testPU TRACE [main] openjpa.Query - Executing query: Query: org.apa= che.openjpa.kernel.QueryImpl@be4f81; candidate class: class entities.Person= ; query: null 1108 testPU TRACE [main] openjpa.jdbc.SQL - ex= ecuting prepstmnt 26531336 SELECT AVG(t0.length) FROM Person t0 WHERE (t0.a= ge > ?) GROUP BY (t0.age / ?) [params=3D(int) 20] You can clearly see that the query has two parameter placeholders but only = one value is provided. Shall I report this as a bug or am I doing something wrong in my code? (As a workaround I can call setHint("openjpa.hint.UseLiteralInSQL", "true")= on em.createQuery(query). This doesn't work in my application because ther= e is a bug where boolean literals aren't correctly handled: https://issues.= apache.org/jira/browse/OPENJPA-2534. I think this is solved in the upcoming= release.) Thank you, Henno