Return-Path: Delivered-To: apmail-incubator-cayenne-user-archive@locus.apache.org Received: (qmail 96673 invoked from network); 18 May 2006 23:05:47 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 18 May 2006 23:05:47 -0000 Received: (qmail 44671 invoked by uid 500); 18 May 2006 23:05:46 -0000 Delivered-To: apmail-incubator-cayenne-user-archive@incubator.apache.org Received: (qmail 44648 invoked by uid 500); 18 May 2006 23:05:46 -0000 Mailing-List: contact cayenne-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cayenne-user@incubator.apache.org Delivered-To: mailing list cayenne-user@incubator.apache.org Received: (qmail 44633 invoked by uid 99); 18 May 2006 23:05:46 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 18 May 2006 16:05:46 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of mkienenb@gmail.com designates 64.233.182.188 as permitted sender) Received: from [64.233.182.188] (HELO nf-out-0910.google.com) (64.233.182.188) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 18 May 2006 16:05:44 -0700 Received: by nf-out-0910.google.com with SMTP id m19so432446nfc for ; Thu, 18 May 2006 16:05:23 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=tMOdkvi9vuVqE5hSQcRm/SlsHxAgn0GZyh94/cLptXDaMuYSPe7PkjseNVAgi17bqq50SIwuE/GVKKyGYCF8UDKKvBs0V7S9JZgx5dV+TQ2FS0+DIV+WaFFuoF7KUiz6T/OVVZGHey4ADC+BjfBv9nMJvR9g0pQJ1QA/bYbUmu4= Received: by 10.48.163.3 with SMTP id l3mr971092nfe; Thu, 18 May 2006 16:05:23 -0700 (PDT) Received: by 10.48.211.12 with HTTP; Thu, 18 May 2006 16:05:23 -0700 (PDT) Message-ID: <8f985b960605181605h2fe4d83dn68335950ef8f2f0d@mail.gmail.com> Date: Thu, 18 May 2006 19:05:23 -0400 From: "Mike Kienenberger" To: cayenne-user@incubator.apache.org Subject: Re: Error when join table spans datamaps In-Reply-To: <8f985b960605181555s1a8b9e6cxfc283bee3dbd67a2@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <8f985b960605181501k1c61f2aenaad1d2e2ea6d763e@mail.gmail.com> <8f985b960605181528g5ef5ef2fsd565b775df8af368@mail.gmail.com> <37FA7EDA-6543-4F94-9415-5AA4D1D07C5C@objectstyle.org> <8f985b960605181555s1a8b9e6cxfc283bee3dbd67a2@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N On 5/18/06, Mike Kienenberger wrote: > This is my first-pass at solving the problem at the application level Cleaned up version that can go in the Base DataObject class. protected List getToManyRelationshipTheHardWay(String targetPrimaryKey, String joinTable, String sourcePrimaryKey, Class targetClass) { String sql =3D "select distinct(" + targetPrimaryKey + ") as ID from " + joinTable + " where " + sourcePrimaryKey + " =3D $PRIMARY_KEY"; // set parameters and run it... Map parameters =3D new HashMap(); parameters.put("PRIMARY_KEY", getPrimaryKey()); SQLTemplate rawSelect =3D new SQLTemplate(getClass(), sql, true); rawSelect.setParameters(parameters); rawSelect.setFetchingDataRows(true); List distinctFKList =3D getDataContext().performQuery(rawSelect); List toManyList =3D new ArrayList(distinctFKList.size()); Iterator foreignKeyIterator =3D distinctFKList.iterator(); while (foreignKeyIterator.hasNext()) { DataRow dataRow =3D (DataRow) foreignKeyIterator.next(); Object primaryKey =3D (Object) dataRow.get("ID"); if (null =3D=3D primaryKey) continue; toManyList.add(DataObjectUtils.objectForPK(getDataContext(), targetClass, primaryKey)); } return toManyList; }