Return-Path: Delivered-To: apmail-cayenne-user-archive@www.apache.org Received: (qmail 887 invoked from network); 8 Apr 2009 01:29:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 8 Apr 2009 01:29:01 -0000 Received: (qmail 87282 invoked by uid 500); 8 Apr 2009 01:29:01 -0000 Delivered-To: apmail-cayenne-user-archive@cayenne.apache.org Received: (qmail 87251 invoked by uid 500); 8 Apr 2009 01:29:01 -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 87241 invoked by uid 99); 8 Apr 2009 01:29:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Apr 2009 01:29:01 +0000 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 ari@ish.com.au designates 59.167.240.32 as permitted sender) Received: from [59.167.240.32] (HELO fish.ish.com.au) (59.167.240.32) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Apr 2009 01:28:51 +0000 Received: from ip-148.ish.com.au ([203.29.62.148]:49947) by fish.ish.com.au with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) (envelope-from ) id 1LrNOz-00044G-0e for user@cayenne.apache.org; Wed, 08 Apr 2009 12:20:33 +1000 Message-Id: From: Aristedes Maniatis To: user@cayenne.apache.org In-Reply-To: <315763.11044.qm@web111104.mail.gq1.yahoo.com> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v930.3) Subject: Re: "Can't get primary key from temporary id" :( Date: Wed, 8 Apr 2009 11:28:25 +1000 References: <315763.11044.qm@web111104.mail.gq1.yahoo.com> X-Mailer: Apple Mail (2.930.3) X-Virus-Checked: Checked by ClamAV on apache.org On 08/04/2009, at 11:03 AM, Joseph Schmidt wrote: >> * write the record to database, fetch it back again and >> then you'll have the primary key > Than this is not the same transaction :(. Correct. This is a limitation of how databases work, not Cayenne. You can't have a primary key until you write the record, unless you do something tricky like using a nanosecond timestamp hashed with the MAC address of your machine and the number you first thought of. >> * create a relationship between A and B > In this particular case, there's no relationship because the > 'id' from entity A is written to a text field in entity B together > with other strings, e.g. "Entity A with #id added at #date..." > So it's impossible to map here a relationship :(. Therein lies the danger of exposing primary keys to the user. I'd recommend you keep keys for relating data and have another generated number for this sort of thing. Or else, map a relationship and have your text message: > Entity A added at #date... Then put the related id into another attribute. > In other usage scenarios I have, e.g. for entity C, there's no > Cayenne relationship because it would mean to connect it with every > other table. That might be a good case for using inheritance. >> If you find yourself using the primary keys directly very >> often, you are probably not using Cayenne in the manner it >> was intended. The idea is that it removes you from thinking >> about database-centric issues like primary keys and just >> think about objects and how they relate to each other. >> Mostly. > Well, I'm not sure about Cayenne, but the entire RESt architecture > is based around the idea of using 'id's to identify entities (but > not just RESt). > If Cayenne can't play simply with 'id's (and it's supposed to be > used without them) than I think it automatically excludes itself > from most web applications :(, since most of them rely on sending > the 'id's back and forth. Cayenne can quite happily play with ids if that is what you need. My point was that if you are accessing the ids directly and manually joining up records with them, then you may be missing some of the power of Cayenne. But without knowing the details, I couldn't say for sure. > Is there no other way to get those IDs? > How to do e.g. audit with Cayenne? Mostly the audit string or record > must be in the same transaction with with what they log. Look at the documentation for lifecycle events. That is probably the best solution for this. Ari Maniatis --------------------------> ish http://www.ish.com.au Level 1, 30 Wilson Street Newtown 2042 Australia phone +61 2 9550 5001 fax +61 2 9550 4001 GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A