Return-Path: Delivered-To: apmail-cayenne-user-archive@www.apache.org Received: (qmail 86800 invoked from network); 27 Dec 2007 18:39:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 27 Dec 2007 18:39:04 -0000 Received: (qmail 40097 invoked by uid 500); 27 Dec 2007 18:38:53 -0000 Delivered-To: apmail-cayenne-user-archive@cayenne.apache.org Received: (qmail 40086 invoked by uid 500); 27 Dec 2007 18:38:52 -0000 Mailing-List: contact user-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cayenne.apache.org Delivered-To: mailing list user@cayenne.apache.org Received: (qmail 40077 invoked by uid 99); 27 Dec 2007 18:38:52 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Dec 2007 10:38:52 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of robert.zeigler@gmail.com designates 64.233.178.241 as permitted sender) Received: from [64.233.178.241] (HELO hs-out-2122.google.com) (64.233.178.241) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Dec 2007 18:38:30 +0000 Received: by hs-out-2122.google.com with SMTP id 4so2312296hsl.4 for ; Thu, 27 Dec 2007 10:38:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:from:to:in-reply-to:content-type:content-transfer-encoding:mime-version:subject:date:references:x-mailer:sender; bh=BH0Us+k10GNwXAeSDRjYEzYp5DlTL3rFZF85PPdLbxQ=; b=l52tP/SRr335xQ5yos0mCnPyBC0h8b5FpVqHd9k+oWoGy9R8YjiII0jPpJJspmMLUJusxH+iAXbKN55eHcju9vwogWTGNASAgrctvhJsCjwG2Q2hEuHK3ZiSShrjeanYfCnColh8GQ/drwksVXff421xXGL5f3fLfM5g7+2y0/Q= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:from:to:in-reply-to:content-type:content-transfer-encoding:mime-version:subject:date:references:x-mailer:sender; b=ja5Nu5QXev9fJkaprsIiL9IHUiSJMeThPpUXyNHLY8/NwGlSCa5CwxzRgYza7mtzITTrUKwduEmhGZhgjvTMnX9/6pvZXXB+04yvYgXq/AO7z2zdQxR8uYeaPQMjfvCorRP//RRIEqyWK2rtyDEaQ5OKzbj2RBvIwt0RYBPCsPU= Received: by 10.100.33.19 with SMTP id g19mr17118112ang.117.1198780610897; Thu, 27 Dec 2007 10:36:50 -0800 (PST) Received: from ?192.168.0.2? ( [70.129.111.165]) by mx.google.com with ESMTPS id 7sm225470nzn.33.2007.12.27.10.36.46 (version=SSLv3 cipher=OTHER); Thu, 27 Dec 2007 10:36:48 -0800 (PST) Message-Id: <40D0E5CD-7892-4E4C-9269-8761168DB82C@puregumption.com> From: Robert Zeigler To: user@cayenne.apache.org In-Reply-To: Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v915) Subject: Re: Design Issue: unique value Date: Thu, 27 Dec 2007 12:36:43 -0600 References: X-Mailer: Apple Mail (2.915) Sender: robert zeigler X-Virus-Checked: Checked by ClamAV on apache.org Hi Joe, Depends on if you need incrementally unique identifiers, or if you need just need a unique number. I have situations where I need unique "transaction ids", but they don't have to be ordered in any particular manner. I use java's random number generation facilities to generate a random number, then attempt to select a datarow from the database with that number; if I successfully select one, the number isn't unique and the process is repeated until I get a unique number. I use 9 digit numbers, so the likelihood of ever generating the same number twice is very small, and in practice, the loop never gets executed twice. Robert On Dec 27, 2007, at 12/2712:26 PM , Joe Baldwin wrote: > This is an upper level design question associated with how to best > generate a unique value using Cayenne and MySQL. > > Step 1: > I have an existent Entity with a primary key (oid). Per the Cayenne- > recommended best practices I am avoiding direct access of this > primary key and have created another attribute (orderID) that must > be unique. So upon doing my Cayenne homework I read that the > standard behavior in the DBMS model and the ORM model is to support > only one auto-generated column and this is typically the PK column > not related to my data abstraction. > > Step 2: > So then I thought, well I will just use the MySQL "MAX()" function, > find the max value, increment and voila I have generate my own > unique number. When I tried to implement this design I ran into > problems with SQLTemplate query attempting to bind the result of > MAX(orderID) to an existent data object. > > Step 3: > I guess I could always execute a "select *" on the entity and find > the max attribute-value with a "for" loop, but that seems kind of > Neanderthal. OK, so I am now thinking someone must have solved this > sort of design issue before I bumped into it. What is the best way > to solve this issue using Cayenne design patterns? > > Thanks, > Joe > > >