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 902776945 for ; Tue, 28 Jun 2011 14:58:24 +0000 (UTC) Received: (qmail 42436 invoked by uid 500); 28 Jun 2011 14:58:24 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 42349 invoked by uid 500); 28 Jun 2011 14:58:23 -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 42337 invoked by uid 99); 28 Jun 2011 14:58:23 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Jun 2011 14:58:23 +0000 X-ASF-Spam-Status: No, hits=2.0 required=5.0 tests=SPF_NEUTRAL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [216.139.236.26] (HELO sam.nabble.com) (216.139.236.26) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Jun 2011 14:58:18 +0000 Received: from jim.nabble.com ([192.168.236.80]) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1QbZjg-0000od-Iu for users@openjpa.apache.org; Tue, 28 Jun 2011 07:57:56 -0700 Date: Tue, 28 Jun 2011 07:57:56 -0700 (PDT) From: Georg Nozicka To: users@openjpa.apache.org Message-ID: <1309273076564-6525216.post@n2.nabble.com> In-Reply-To: <1305909712577-6386782.post@n2.nabble.com> References: <1305651727430-6373899.post@n2.nabble.com> <1305909712577-6386782.post@n2.nabble.com> Subject: Re: Criteria API; AND 1 = 1 in WHERE Clause MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hello, I tried to reduce the sample as far as possible. First the code: CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(UnternehmenUrv.class); Root untRoot = cq.from(UnternehmenUrv.class); cq.select(untRoot); Join<UnternehmenUrv, UnameHist> unameHistJoin = untRoot.join( UnternehmenUrv_.unameHist.getName(), JoinType.INNER); Join<UnternehmenUrv, Adresse> adresseJoin = untRoot.join( UnternehmenUrv_.adressen.getName(), JoinType.INNER); List predicates = new ArrayList(); ParameterExpression pe = cb.parameter(String.class, UnameHist_.unameL.getName()); predicates.add(cb.like( unameHistJoin.get(UnameHist_.unameL).as(String.class), pe)); ParameterExpression peStr = cb.parameter(String.class, Adresse_.strL.getName()); predicates.add(cb.like(adresseJoin.get(Adresse_.strL).as(String.class), peStr)); cq.where(cb.and(predicates.toArray(new Predicate[0]))); TypedQuery tq = em.createQuery(cq); tq.setParameter(UnameHist_.unameL.getName(), "nozick%"); tq.setParameter(Adresse_.strL.getName(), "fadenw%"); return tq.getResultList(); The toString for the CriteriaQuery instance gives the following output: SELECT u FROM UnternehmenUrv u INNER JOIN u.unameHist ? INNER JOIN u.adressen ? WHERE (u.unameHist.unameL LIKE :unameL AND u.adressen.strL LIKE :strL) The jpa trace for the generated SQL is like this: SELECT t0.OID, t0.UKOID, t0.UNAME, t0.UNTID FROM udbq.TUUNT_UNTERNEHMEN t0 INNER JOIN udbq.TUUNT_UNAME_HIST t1 ON t0.OID = t1.UOID INNER JOIN udbq.TUUNT_ADRESSE t2 ON t0.OID = t2.BEZOID WHERE (t1.UNAME_L LIKE ? ESCAPE '\' AND t2.STR_L LIKE ? ESCAPE '\' AND 1 = 1) [params=?, ?] Any ideas? -- View this message in context: http://openjpa.208410.n2.nabble.com/Criteria-API-AND-1-1-in-WHERE-Clause-tp6373899p6525216.html Sent from the OpenJPA Users mailing list archive at Nabble.com.