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 C6DC7173CB for ; Thu, 23 Apr 2015 13:42:49 +0000 (UTC) Received: (qmail 69541 invoked by uid 500); 23 Apr 2015 13:42:46 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 69500 invoked by uid 500); 23 Apr 2015 13:42:46 -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 69488 invoked by uid 99); 23 Apr 2015 13:42:46 -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 13:42:46 +0000 X-ASF-Spam-Status: No, hits=2.4 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: message received from 54.164.171.186 which is an MX secondary for users@openjpa.apache.org) Received: from [54.164.171.186] (HELO mx1-us-east.apache.org) (54.164.171.186) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Apr 2015 13:42:41 +0000 Received: from mail-ob0-f182.google.com (mail-ob0-f182.google.com [209.85.214.182]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTPS id 304E843CCF for ; Thu, 23 Apr 2015 13:42:21 +0000 (UTC) Received: by oblw8 with SMTP id w8so13621296obl.0 for ; Thu, 23 Apr 2015 06:42:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=tCatN137ELQT5efXpr9/VFKqf0a91WnxinvYwz+l7pE=; b=D7W5THkTqOIEyA+fxHe6Im11rXjFkQYZ8jo8oggOUc1y4/lWysGNc9C5bveUVz1s4g tqme8VCedmgmFUOF5BUmc6PsmR1cyGL0xlcyjakdAmmjw6f+aBZRDBloVNWFwvlMUS2D EUtFDz2sHxjJjvHZKoo18aRKr1ZzksvKzV9spZ8p1vWVGJUenRVORfJ2+aBUag3NtOXt EZzlkOjRA4AVA/vfYQNUPBgb+eLF1tdkFgSOOiI4ad/uYy1aCvZBECKeTkTK/VuxUOlA y2U9dliUTc2619cFYi5cIrP/lRAvuBNyTPlU2Qpj/0xiK3DfA3T+1aUZM6HNydjHXL/m g4IQ== MIME-Version: 1.0 X-Received: by 10.182.68.103 with SMTP id v7mr2534826obt.82.1429796540705; Thu, 23 Apr 2015 06:42:20 -0700 (PDT) Received: by 10.60.167.49 with HTTP; Thu, 23 Apr 2015 06:42:20 -0700 (PDT) In-Reply-To: References: <2FFAFD73C8FCEA4FB07C5E997664B1A039CE10AD@HMS11.hm.local> <2FFAFD73C8FCEA4FB07C5E997664B1A039CE10CA@HMS11.hm.local> Date: Thu, 23 Apr 2015 08:42:20 -0500 Message-ID: Subject: Re: criteria API generates a parameter for literal in group by but does not provide the value From: Rick Curtis To: users Content-Type: multipart/alternative; boundary=e89a8fb1ef2ce8f1f0051464727d X-Virus-Checked: Checked by ClamAV on apache.org --e89a8fb1ef2ce8f1f0051464727d Content-Type: text/plain; charset=ISO-8859-1 > Shall I report this as a bug or am I doing something wrong in my code? I vote bug On Thu, Apr 23, 2015 at 6:43 AM, Mark Struberg wrote: > Thanks Henno! > > Not quite sure if this workaround is good enough or whether we should try > to solve this properly. > I plan to do a follow up release for 2.4.0 rather soonish. So thanks for > your test case. > > Did you already look at the OpenJPA codebase? Are you interested in > turning this sample code into a unit test? > > > txs and LieGrue, > strub > > > > > Am 23.04.2015 um 12:32 schrieb Henno Vermeulen : > > > > One addition (my question is still open). > > > > I can confirm that a valid workaround for this problem is to use > setHint("openjpa.hint.UseLiteralInSQL", "true") and updating to OpenJPA > 2.4.0 which is available in Maven central since a few days. > > > > Henno > > > > -----Oorspronkelijk bericht----- > > Van: Henno Vermeulen [mailto:henno@huizemolenaar.nl] > > Verzonden: donderdag 23 april 2015 11:49 > > Aan: users@openjpa.apache.org > > Onderwerp: criteria API generates a parameter for literal in group by > but does not provide the value > > > > Hello, > > > > I have a query created using the criteria API where I group by an > expression that contains a small calculation using literal values. > > > > OpenJPA generates the correct SQL but does not provide the value of the > generated parameter in the group by clause. The query fails with a SQL > exception "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 = em.getCriteriaBuilder(); > > CriteriaQuery query = > cb.createQuery(Double.class); > > Root person = query.from(Person.class); > > > > Expression averageLength = > cb.avg(person. get("length")); > > CriteriaQuery select = > query.select(averageLength); > > > > 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(query).getResultList()); > > > > Whe running this query with trace and displaying parameters on I get: > > > > 1067 testPU TRACE [main] openjpa.Query - Executing query: Query: > org.apache.openjpa.kernel.QueryImpl@be4f81; candidate class: class > entities.Person; query: null > > 1108 testPU TRACE [main] openjpa.jdbc.SQL - > executing prepstmnt 26531336 SELECT AVG(t0.length) FROM Person t0 WHERE > (t0.age > ?) GROUP BY (t0.age / ?) [params=(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 there 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 > > > > -- *Rick Curtis* --e89a8fb1ef2ce8f1f0051464727d--