Return-Path: Delivered-To: apmail-cayenne-user-archive@www.apache.org Received: (qmail 11768 invoked from network); 22 Jun 2007 07:30:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 22 Jun 2007 07:30:05 -0000 Received: (qmail 60130 invoked by uid 500); 22 Jun 2007 07:30:08 -0000 Delivered-To: apmail-cayenne-user-archive@cayenne.apache.org Received: (qmail 59886 invoked by uid 500); 22 Jun 2007 07:30:07 -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 59877 invoked by uid 99); 22 Jun 2007 07:30:07 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Jun 2007 00:30:07 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [195.4.92.90] (HELO mout0.freenet.de) (195.4.92.90) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Jun 2007 00:30:02 -0700 Received: from [195.4.92.11] (helo=mx1.freenet.de) by mout0.freenet.de with esmtpa (Exim 4.68) (envelope-from ) id 1I1daO-0001do-Jq for user@cayenne.apache.org; Fri, 22 Jun 2007 09:29:40 +0200 Received: from fnhh-svmexfe002.freenet-ag.de ([194.97.108.43]:5509) by mx1.freenet.de with esmtp (port 25) (Exim 4.68 #1) id 1I1daO-0007VS-Ez for user@cayenne.apache.org; Fri, 22 Jun 2007 09:29:40 +0200 Received: from FNHH-SVMEXDB002.Freenet-AG.de ([195.4.20.141]) by FNHH-SVMEXFE002.Freenet-AG.de with Microsoft SMTPSVC(6.0.3790.1830); Fri, 22 Jun 2007 09:30:08 +0200 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: AW: creating/saving transient objects to database Date: Fri, 22 Jun 2007 09:30:07 +0200 Message-ID: <49D23F7404DC5B4086D7352312597E0F01116316@FNHH-SVMEXDB002.Freenet-AG.de> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: creating/saving transient objects to database Thread-Index: Ace0RTXfwPhczIdGSK6Ei61BlMC+tAACKoqwABQq9LA= References: From: =?iso-8859-1?Q?Peter_Schr=F6der?= To: X-OriginalArrivalTime: 22 Jun 2007 07:30:08.0246 (UTC) FILETIME=[28E84960:01C7B49F] X-Virus-Checked: Checked by ClamAV on apache.org this approach has the downside that you may run into concurrency issues = (check than act). you may get a duplicate even if you first check for an existing entry. this is really tricky in webapplications... kind regards, peter -----Urspr=FCngliche Nachricht----- Von: Fredrik Liden [mailto:fliden@translate.com]=20 Gesendet: Freitag, 22. Juni 2007 00:10 An: user@cayenne.apache.org Betreff: RE: creating/saving transient objects to database If you're calling newObject you'll get a registered object with PersistenceState.NEW. so consequently the commit tries to insert it. I'm thinking at some point you'll need to manually check if the object exists in the database or not based on some criteria. Maybe you can create a service class that checks using a query if the Pojo object exists in the db. If it does it returns the existing DataObject and if not it returns the object using newObject. Then the persistenceState will be either NEW or COMMITED and commit will trigger insert and update respectively. Of course the Cayenne guys probably have some other nifty way to do it. Fredrik =20 -----Original Message----- From: Michael Lepine [mailto:mikelepine@gmail.com]=20 Sent: Thursday, June 21, 2007 2:46 PM To: user@cayenne.apache.org Subject: creating/saving transient objects to database I've got a situation where I've got strict POJO objects that I'll need to copy data from and into my generated Cayenne classes. My issue is that when I copy the data from the bean to the Cayenne class, I don't know whether the object exists or not. Thus, I create the Cayenne class instance using DataContext.newObject(). Obviously, when I call DataContext.commitChanges(), an insert is being attempted on the corresponding table even if a record already exists in the database. Is there a way to create the Cayenne instance so that the persistent layer will know to check whether the record exists and update it instead of always attempting an insert? Any help and guidance are appreciated.