From dev-return-26151-archive-asf-public=cust-asf.ponee.io@openjpa.apache.org Tue Apr 23 07:21:02 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id EB4B218076D for ; Tue, 23 Apr 2019 09:21:01 +0200 (CEST) Received: (qmail 23699 invoked by uid 500); 23 Apr 2019 07:21:01 -0000 Mailing-List: contact dev-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list dev@openjpa.apache.org Received: (qmail 23688 invoked by uid 99); 23 Apr 2019 07:21:01 -0000 Received: from mailrelay1-us-west.apache.org (HELO mailrelay1-us-west.apache.org) (209.188.14.139) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Apr 2019 07:21:01 +0000 Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 54D4EE2832 for ; Tue, 23 Apr 2019 07:21:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 1104425807 for ; Tue, 23 Apr 2019 07:21:00 +0000 (UTC) Date: Tue, 23 Apr 2019 07:21:00 +0000 (UTC) From: "Michael Wiles (JIRA)" To: dev@openjpa.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (OPENJPA-2788) Anonymous parameters are not being picked when adding via CriteriaBuilder MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/OPENJPA-2788?page=3Dcom.atlass= ian.jira.plugin.system.issuetabpanels:all-tabpanel ] Michael Wiles updated OPENJPA-2788: ----------------------------------- Priority: Critical (was: Major) > Anonymous parameters are not being picked when adding via CriteriaBuilder > ------------------------------------------------------------------------- > > Key: OPENJPA-2788 > URL: https://issues.apache.org/jira/browse/OPENJPA-2788 > Project: OpenJPA > Issue Type: Bug > Components: criteria > Affects Versions: 3.1.0 > Reporter: Michael Wiles > Priority: Critical > > Something that is almost certainly introduced via fixes for=C2=A0OPENJPA-= 2785 and OPENJPA-2733 is that anonymous parameters are not picked up. > The following piece of code does not add the second parameter successfull= y and thus the test fails. > With a Member entity that has a place and a name field: > {code:java} > Member m =3D new Member(1, "dave"); > m.setAge(5); > m.setPlace("capetown"); > em.persist(m); > CriteriaBuilder cb =3D em.getCriteriaBuilder(); > CriteriaQuery q =3D cb.createQuery(Member.class); > Root c =3D q.from(Member.class); > ParameterExpression name =3D cb.parameter(String.class); > ParameterExpression place =3D cb.parameter(String.class); > CriteriaQuery where =3D q.select(c).where(cb.equal(c.get(= "name"), name), cb.equal(c.get("place"), place)); > TypedQuery query =3D em.createQuery(where); > query.setParameter(name, "dave"); > query.setParameter(place, "capetown"); > List results =3D query.getResultList(); > assertThat(results).isNotEmpty(); > {code} > With query and parameter logging on you that the the sql call is made wit= h the same parameter twice... > {noformat} > executing prepstmnt 2078396010 SELECT t0.i= d, t0.age, t0.name, t0.place FROM Member t0 WHERE (t0.name =3D ? AND t0.pla= ce =3D ?) [params=3D(String) dave, (String) dave] > {noformat} > And this kinda makes sense as this is what the CriteriaQueryImpl.register= Parameter looks like: > {code:java} > /** > * Registers the given parameter. > */ > void registerParameter(ParameterExpressionImpl p) { > for (Object k : _params.keySet()) { > if (p.paramEquals(k)) { > // If a named ParameterExpressin did already get register= ed > // with that exact name, then we do ignore it. > // If we do a query.setParameter("someParamName", Bla) > // then it must uniquely identify a Parameter. > return; > } > } > p.setIndex(_params.size()); > _params.put(p, p.getJavaType()); > } > {code} > And [paramEquals|https://github.com/apache/openjpa/blob/9f26ed29bf31b5c8a= b68c5257d42e8c88765cf9b/openjpa-persistence/src/main/java/org/apache/openjp= a/persistence/criteria/ParameterExpressionImpl.java#L142] will not differen= tiate between two anonymous parameters. > So I suspect we are going to need some mechanism for differentiating betw= een two anonymous parameters - and if we did this then I suspect the issue = that caused this in the first place might also be resolved. Possibly add so= me kind of counter or something that can give identity to anonymous paramet= ers. > =C2=A0Added test to=C2=A0[https://github.com/michaelwiles/openjpa-bugs] -- This message was sent by Atlassian JIRA (v7.6.3#76005)