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 2B56C996C for ; Mon, 20 Feb 2012 20:43:17 +0000 (UTC) Received: (qmail 28343 invoked by uid 500); 20 Feb 2012 20:43:16 -0000 Delivered-To: apmail-cayenne-user-archive@cayenne.apache.org Received: (qmail 28322 invoked by uid 500); 20 Feb 2012 20:43:16 -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 28314 invoked by uid 99); 20 Feb 2012 20:43:16 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Feb 2012 20:43:16 +0000 X-ASF-Spam-Status: No, hits=1.8 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,FSL_RCVD_USER,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of yk77770@gmail.com designates 209.85.214.43 as permitted sender) Received: from [209.85.214.43] (HELO mail-bk0-f43.google.com) (209.85.214.43) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Feb 2012 20:43:10 +0000 Received: by bkcjg15 with SMTP id jg15so8788585bkc.16 for ; Mon, 20 Feb 2012 12:42:49 -0800 (PST) Received-SPF: pass (google.com: domain of yk77770@gmail.com designates 10.204.149.209 as permitted sender) client-ip=10.204.149.209; Authentication-Results: mr.google.com; spf=pass (google.com: domain of yk77770@gmail.com designates 10.204.149.209 as permitted sender) smtp.mail=yk77770@gmail.com; dkim=pass header.i=yk77770@gmail.com Received: from mr.google.com ([10.204.149.209]) by 10.204.149.209 with SMTP id u17mr12317135bkv.46.1329770569960 (num_hops = 1); Mon, 20 Feb 2012 12:42:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=LtFEeaiKqYblEPaFlK9RsKTZS0HJmFyJUrkxQqXtdRI=; b=KAmVZmGSlLAR1WXnF2BrrVmT8lTtztWipV/FehIgO+auES0ItxVm44SaDwkITfcWrJ XZOyKvEt5d91vqf/mGoaEYiLazFnUZ1NCn5XbIuED7PWGIHtTBa5cDGFSXoZfB2NHtwG 9TUSle/KZXbiiiNOQz+BVGQKA3ux9gABLMy6A= MIME-Version: 1.0 Received: by 10.204.149.209 with SMTP id u17mr9947059bkv.46.1329770569886; Mon, 20 Feb 2012 12:42:49 -0800 (PST) Received: by 10.205.133.131 with HTTP; Mon, 20 Feb 2012 12:42:49 -0800 (PST) In-Reply-To: <0A1740BF-44E2-4506-B8B4-05CD4E68BD40@objectstyle.org> References: <0A1740BF-44E2-4506-B8B4-05CD4E68BD40@objectstyle.org> Date: Mon, 20 Feb 2012 21:42:49 +0100 Message-ID: Subject: Re: Cayenne external transaction From: YK 7 To: user@cayenne.apache.org Content-Type: multipart/alternative; boundary=0015175cd03a736c7e04b96b56aa X-Virus-Checked: Checked by ClamAV on apache.org --0015175cd03a736c7e04b96b56aa Content-Type: text/plain; charset=ISO-8859-1 Thanks for this brilliant answer Andrus! However, I still have a question. Suppose that we have two databases and that we commit to the second one only if the commit to the first db succeeds. If I well understood, here I have to use external tx because it offers more granularity. Is it better to have an ObjectContext per DataNode (and not per DataDomain) so that we can handle all cases? Thanks On Sun, Feb 19, 2012 at 1:51 PM, Andrus Adamchik wrote: > External transactions allow you to use container-managed DataSource and > tie Cayenne in to container-managed JDBC transactions. So essentially if a > container does a commit or rollback on a Connection, this will > commit/rollback everything that was flushed via Cayenne or other JDBC > clients since the start of the transaction. > > DataNode by itself is stateless. It is just a driver on top of JDBC driver > if you may. So no problems there. > > ObjectContext state is not tied directly to the transaction. Its commit > within an external tx is a flush to DB that will be committed or rolled > back at some later point at tx end. You can do multiple ObjectContext > commits within the same tx to update data incrementally, etc. ObjectContext > rollback is even less related to tx. It just reverts objects in memory back > to their previously known committed state. In many cases you probably do > not want to reuse the context between external transactions. > > And finally, consider whether you really need those external transactions. > 90% of Cayenne apps don't. A common reason to use external tx is when you > want atomic behavior across multiple sources of DB modification (say > Cayenne and raw JDBC) or mixing Cayenne with other non-JDBC transactional > resources (JMS for instance). If you only modify the DB via Cayenne, then > you don't need external tx. This is what makes Cayenne unique in the ORM > space, and so much easier to use. It was compared to a version control > system by other users - you check out a local copy of your objects, you > modify them, and then commit. Only the last step involves a transaction and > Cayenne can handle starting and ending it internally with no user > involvement. > > Cheers, > Andrus > > > > On Feb 18, 2012, at 5:48 PM, YK 7 wrote: > > In Cayenne Modeler, when I disable Cayenne managed transactions, a > message > > saying that the external transaction was used instead during a commit. > > > > How am I supposed to tell my external container to handle transaction if > > cayenne manages DB objects(Node, ObjectContext...) ? > > > > Do you have any working example that shows how to use cayenne with the > same > > circumstances? > > > > thx > > --0015175cd03a736c7e04b96b56aa--