Return-Path: Delivered-To: apmail-openjpa-users-archive@locus.apache.org Received: (qmail 20126 invoked from network); 18 Jul 2007 18:44:00 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 Jul 2007 18:44:00 -0000 Received: (qmail 30617 invoked by uid 500); 18 Jul 2007 18:43:47 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 30600 invoked by uid 500); 18 Jul 2007 18:43:47 -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 30589 invoked by uid 99); 18 Jul 2007 18:43:47 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Jul 2007 11:43:47 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of christian.defoy@gmail.com designates 64.233.184.234 as permitted sender) Received: from [64.233.184.234] (HELO wr-out-0506.google.com) (64.233.184.234) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Jul 2007 11:43:44 -0700 Received: by wr-out-0506.google.com with SMTP id 67so254341wri for ; Wed, 18 Jul 2007 11:43:23 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=tXO3DaoHUUz/RApjTpxP4JBCw7beSsKAGRHsdt0YQB5R8+B+VX+54rUspj4A9qilqL61r9ueeRNUFk355omxEK4rW7VUhERWEiSQWUHXYagcdq4dtKWjkRqGi5GoUT2IQ9muLmFCdJFch6OhGddw7T7xr7a8ALh75zTrTYxjC88= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=V1CGnjt0SJnLeMTppvvhNZheGS9kIIkXEvKhwR4IlVJkGJttKyu3KKOY9lVOBs+ibeN4pRVscc08s1ypA73cQtuENbhiKx+LL0ghgYqK9pu0Kmceh5pt/VrBETbKGJrn7SoGPgcto9f+rvbQDKMr7cz1jtTqxQCUm1XCPl5d8i8= Received: by 10.90.95.11 with SMTP id s11mr1982135agb.1184784203782; Wed, 18 Jul 2007 11:43:23 -0700 (PDT) Received: by 10.90.52.9 with HTTP; Wed, 18 Jul 2007 11:43:23 -0700 (PDT) Message-ID: <967946b0707181143n314ef76ev8d80ac8936a92dbc@mail.gmail.com> Date: Wed, 18 Jul 2007 14:43:23 -0400 From: "Christian Defoy" To: users@openjpa.apache.org Subject: Re: Getting a group of entities by ID In-Reply-To: <79BD8CF5-62AB-4D1A-B017-750B941E12C9@apache.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <967946b0707180639r528286afs1309dc411dee58ba@mail.gmail.com> <469E2224.2040008@bea.com> <79BD8CF5-62AB-4D1A-B017-750B941E12C9@apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Hi Marc, Thanks for the tip. It works fine! That's the functionality I was looking for! I changed the query a bit because it looks like we have to enclose that specific parameter in (). em.createQuery("SELECT x FROM shape x WHERE x.id in (:ids)"); Thank you both for your time! Christian On 7/18/07, Marc Prud'hommeaux wrote: > Christian- > > In additional to what David said, I think should be able to do: > > em.createQuery("SELECT x FROM shape x WHERE x.id in :ids"). > setParameter("ids", Arrays.asList(new Integer[] { 1, 2, 3 })). > getResultlist(); > > > > > > > On Jul 18, 2007, at 7:22 AM, David Ezzio wrote: > > > Hi Christian, > > > > You might consider using the OpenJPAEntityManager.findAll method. The > > expected advantage is that any objects in the datacache won't cause a > > hit to the database. If there is a high likelihood that all > > objects are > > in the datacache, then this is definitely the way to go. If some > > objects will very likely not be in the cache, then you might want to > > investigate. I'm not sure whether it will generate one SQL statement > > for all missing objects or one for each. You might want to turn on > > SQL > > logging to check, > > > > ((OpenJPAEntityManager) em).findAll(...) > > > > Hope this helps, > > > > David > > > > Christian Defoy wrote: > >> Hello, > >> > >> I can't find an easy way of retrieving a group of entities by > >> specifying only their IDs. For example, if I want to get shapes with > >> IDs 1, 2, 4 and 6, do I have to do the following query or is there a > >> better way? > >> > >> SELECT x FROM shape x WHERE x.id = 1 OR x.id = 2 OR x.id = 4 OR > >> x.id = 6 > >> > >> I was thinking of something more along the lines of the IN SQL > >> statement ("WHERE x.id IN (1,2,4,6)") but I haven't found anything to > >> do this. Using SQL queries, I was able to retrieve my shapes but > >> OpenJPA does one select to retrieve the IDs (my SQL query with the IN > >> clause) and then one select per shape it retrieves. That is no > >> different than me doing a find for every shape myself... > >> > >> Thanks in advance! > >> > >> Christian > >> > > > > > > Notice: This email message, together with any attachments, may > > contain information of BEA Systems, Inc., its subsidiaries > > and affiliated entities, that may be confidential, proprietary, > > copyrighted and/or legally privileged, and is intended solely for > > the use of the individual or entity named in this message. If you > > are not the intended recipient, and have received this message in > > error, please immediately return this by email and then delete it. > >