Return-Path: Delivered-To: apmail-cayenne-user-archive@www.apache.org Received: (qmail 58929 invoked from network); 15 Jul 2008 21:49:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 15 Jul 2008 21:49:54 -0000 Received: (qmail 16405 invoked by uid 500); 15 Jul 2008 21:49:53 -0000 Delivered-To: apmail-cayenne-user-archive@cayenne.apache.org Received: (qmail 16392 invoked by uid 500); 15 Jul 2008 21:49:53 -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 16381 invoked by uid 99); 15 Jul 2008 21:49:53 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Jul 2008 14:49:53 -0700 X-ASF-Spam-Status: No, hits=-0.3 required=10.0 tests=RCVD_IN_DNSWL_LOW,SPF_SOFTFAIL X-Spam-Check-By: apache.org Received-SPF: softfail (athena.apache.org: transitioning domain of fliden@translate.com does not designate 66.180.96.58 as permitted sender) Received: from [66.180.96.58] (HELO mx.cbeyond.com) (66.180.96.58) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Jul 2008 21:48:59 +0000 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAPK3fEhAzyck/2dsb2JhbACweA X-IronPort-AV: E=Sophos;i="4.30,368,1212379200"; d="scan'208";a="87446267" Received: from mail.translate.com (HELO mail2007.translate.com) ([64.207.39.36]) by mx.cbeyond.com with ESMTP; 15 Jul 2008 17:48:22 -0400 Received: from 192.168.5.37 ([192.168.5.37] helo=mail2007.translate.com) by ASSP.nospam; 15 Jul 2008 15:48:11 -0600 Received: from orion.helios.local ([192.168.5.37]) by orion.helios.local ([192.168.5.37]) with mapi; Tue, 15 Jul 2008 15:48:21 -0600 From: Fredrik Liden To: "'user@cayenne.apache.org'" Date: Tue, 15 Jul 2008 15:48:20 -0600 Subject: RE: What to do with new objects if validation fails on Commit Thread-Topic: What to do with new objects if validation fails on Commit Thread-Index: Acjmue9t1k2iNfJASc+xGV7dTUoELAACdOXQ Message-ID: <4236658BB877A542A66660614300B18525F3B572F6@orion.helios.local> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Virus-Checked: Checked by ClamAV on apache.org Hi, every time you do context.commit(); you should probably have context.ro= llbackChanges(); in the catch statement to set it back to the original stat= e and avoid the same validation error on every consecutive commit. And poss= ibly forward the validation error to the user in some form. Fredrik -----Original Message----- From: Devyandu [mailto:devyandu@gmail.com] Sent: Tuesday, July 15, 2008 1:49 PM To: user@cayenne.apache.org Subject: What to do with new objects if validation fails on Commit I am new to Cayenne but enjoying using it, I have a question about what to do with new or modified objects when a validation failure or runtime exception happens on Commit. This is my Environment TomCat 5.0 Java 1.4.2 Cayenne 2.0.4 Struts For example in my save new painting Actionclass DataContext context=3Dcontext.getgetThreadDataContext(); //Get artist object Artist a=3D (Artist)DataObjectUtils.objectForPK(context,State.class, 1); Painting p =3D (Painting)context.newObject(Painting.class); //Fill in painting from Form post (I use Dozer) . . p.setToArtist(a); try { context.commit(); } catch (Exception e) { //What to do here ??? } What do I do when there is an exception, (unregisterobjects?) I do not want the modified Artist and the new Painting sitting on the context. Because Cayenne would try to commit them if the user went to the gallery screen now and changed a Gallery. Should I not use the threadDataContext in a web app and create a new data context for each save page to avoid this problem. What is the convention for a web/struts app. I am sure many people have encountered and solved this before me. Thanks in advance, DB