Return-Path: X-Original-To: apmail-cayenne-user-archive@www.apache.org Delivered-To: apmail-cayenne-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3F10ECAFE for ; Wed, 6 Jun 2012 13:09:26 +0000 (UTC) Received: (qmail 55138 invoked by uid 500); 6 Jun 2012 13:09:26 -0000 Delivered-To: apmail-cayenne-user-archive@cayenne.apache.org Received: (qmail 55125 invoked by uid 500); 6 Jun 2012 13:09:26 -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 55117 invoked by uid 99); 6 Jun 2012 13:09:26 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Jun 2012 13:09:26 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=FSL_RCVD_USER,RCVD_IN_DNSWL_LOW,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [209.85.210.43] (HELO mail-pz0-f43.google.com) (209.85.210.43) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Jun 2012 13:09:19 +0000 Received: by dajz8 with SMTP id z8so13627926daj.16 for ; Wed, 06 Jun 2012 06:08:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding:x-gm-message-state; bh=UUEeO3olnW6aixdEpjdp+9YZqgLmXqQfF7wu78HeaIs=; b=hrD1B9bC5ZrBMX9RibhkZ0AbPyuey5DbdVCrvRsHgoWpLOBlrcYUK1Dm6GGZNstkDC CeredJpR9E0iT5rkKwaccXrQT8MdMMb8wSOqxZK1eGP99rvuaadYuOG6cs4nQD1AUts/ TKgjH7qR65qf6pxWi0gebHvBr9k1CNgTHGqtFyig2hSPDqeCrJJr3IOHjKnCcoi2lmLZ GgPfcZBPUKpXzCYAMZrxxB0VUzSR0trig4ZtjU/Fmv1dOR66t1Bfvc61nLbBpYUTDo4x myKV+f9pZti6YBmfFPJV9DHHw9uTherM/pq/Z8trhKWoGYxt+ieOh00sA7DA1RlVswEW wwOw== Received: by 10.68.237.166 with SMTP id vd6mr57919169pbc.139.1338988137173; Wed, 06 Jun 2012 06:08:57 -0700 (PDT) MIME-Version: 1.0 Received: by 10.68.59.104 with HTTP; Wed, 6 Jun 2012 06:08:35 -0700 (PDT) In-Reply-To: References: <1338925480358-4024219.post@n3.nabble.com> From: Michael Gentry Date: Wed, 6 Jun 2012 09:08:35 -0400 Message-ID: Subject: Re: Transaction Fails - when saving interdependent entities. To: user@cayenne.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Gm-Message-State: ALoCoQlyAPBm9UIagbHezGmQ0mMM4yxgnrw1en8HCdU/Z3uOd/ZnZfbXd0rWHDTH3vV9iDxKn/2L PostgreSQL is a nice DB. Sadly, we are using MySQL here and can't defer the constraints, so we tend to not use constraints. Glad it works nicely for you, though! mrg On Wed, Jun 6, 2012 at 7:58 AM, Bryan Lewis wrote: > This is so cool. =A0The tip about deferred constraints allowed me to get = rid > of my custom EntitySorter code that I've been maintaining for years. =A0T= his > morning I ran scripts to drop all my foreign-key constraints and re-add > them as initially deferred, for example: > > =A0ALTER TABLE alert ADD FOREIGN KEY (add_id) REFERENCES employee (id) > =A0 =A0DEFERRABLE INITIALLY DEFERRED; > > I deleted my CustomEntitySorter code and ran all my tests, including the > acid test that does an insert/delete on all my entities. =A0No failures. > > This technique still protects my data against ham-fisted manual database > edits, or the exceedingly rare bug in my code. =A0Thanks, Michael. > > The embarrassing thing is, deferrable constraints have existed since Orac= le > 8i. =A0I could've used this feature ten years ago if I'd known about it. > (I'm on Postgres 9 now.) > > > > On Tue, Jun 5, 2012 at 4:00 PM, Michael Gentry wro= te: > >> Hi Gilberto, >> >> With Cayenne, you model the relationships between tables/objects and >> Cayenne can build a dependency graph of what needs inserted first >> (mainly useful for auto-generated keys), but currently there is no >> mechanism in Cayenne to model the database constraints which can >> further influence the dependency graph. >> >> I'd say deferred constraints can be useful even for small amounts of >> data. =A0From my perspective, I care about the integrity of the data at >> the end of the transaction, not in the middle, even if the transaction >> only has a few statements. >> >> Turning on the logs (if they aren't already on) is unlikely to help in >> this case. =A0I know from past experience that the dependency graph >> produced by the EntitySorter isn't always the same from run-to-run >> (there can be different, but valid, dependency graphs for a set of >> operations). =A0Most likely deferring the constraints will solve the >> issue. =A0And at least PostgreSQL allows you to do that. =A0:-) >> >> mrg >> >> >> On Tue, Jun 5, 2012 at 3:44 PM, gilbertoca wrote: >> > >> > Michael Gentry-2 wrote >> >> >> >> Cayenne currently does not know about how your database constraints a= re >> >> structured (even though >> >> when it generates the schema it can add some constraints). >> >> >> > >> > I think Cayenne is very intelligent and know the correct order to exec= ute >> > the statements, doesn't it? >> > >> > Michael, in my little experience in Database I would say that the comm= on >> use >> > of the deferred integrity constraints is when dealing with large volum= es >> of >> > data being inserted into tables.[1] >> > >> > Maybe enabling =A0the Cayenne log to show us how the statements are >> ordered we >> > could see another symptom. >> > Regards >> > >> > Gilberto >> > >> > >> > -- >> > View this message in context: >> http://cayenne.195.n3.nabble.com/Transaction-Fails-when-saving-interdepe= ndent-entities-tp4024215p4024219.html >> > Sent from the Cayenne - User mailing list archive at Nabble.com. >>