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 8E52E9EC3 for ; Sat, 17 Mar 2012 08:17:20 +0000 (UTC) Received: (qmail 64795 invoked by uid 500); 17 Mar 2012 08:17:20 -0000 Delivered-To: apmail-cayenne-user-archive@cayenne.apache.org Received: (qmail 64409 invoked by uid 500); 17 Mar 2012 08:17:15 -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 64357 invoked by uid 99); 17 Mar 2012 08:17:14 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 17 Mar 2012 08:17:14 +0000 X-ASF-Spam-Status: No, hits=1.7 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.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; Sat, 17 Mar 2012 08:17:08 +0000 Received: by bkwj5 with SMTP id j5so6860774bkw.16 for ; Sat, 17 Mar 2012 01:16:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=YlTEmHFr+/rB7RxkgjMyfwIN6FlakkAlIx/ucoQk7Uc=; b=wEwdCDmYx6xoVedQlyh77bTtD1tw3GhkD33e5V5vhA4ODYd1p68RLEBjhylDY5Sn7Z 5uaDMIqSHHuiJe6KA+KB1gLkn3DxLD8r5FkoEWG/11t9eKMPEI58ySzEEN1j8Hrca9G5 o7S78jRDRrbqQPccnQWLr5FnqZvJg9QR3TGjDP13euH8XHsg4H4rqdsa64gUQxu/L+ma aRNzHDn9n8JQagB7pxvMOp1vyth+G2ra2PP//pjuIQlnvmol1K+BvxwWBIR1I1oBSD+5 64SI1v//IgICt8/poeArdQIPQEuUpa7TDb5gz2/NLYNaIAk1PA2/SQg8/txeYeB8d1P2 IIAw== MIME-Version: 1.0 Received: by 10.204.136.197 with SMTP id s5mr2081789bkt.9.1331972206576; Sat, 17 Mar 2012 01:16:46 -0700 (PDT) Received: by 10.204.150.76 with HTTP; Sat, 17 Mar 2012 01:16:46 -0700 (PDT) Date: Sat, 17 Mar 2012 09:16:46 +0100 Message-ID: Subject: Transaction Management From: YK 7 To: user@cayenne.apache.org Content-Type: multipart/alternative; boundary=0015175cfbb039451e04bb6bf27f X-Virus-Checked: Checked by ClamAV on apache.org --0015175cfbb039451e04bb6bf27f Content-Type: text/plain; charset=ISO-8859-1 Hi, I'm new to Cayenne and I'm testing the Cayenne's transaction management using the following scenario: I have a simple web application that uses Spring to create singletons(Services, DAOs...) and make the dependencies injection. My example is using two different Databases (MySQL and Oracle) and thus, I have defined two Cayenne Server Runtimes: One for Oracle and one for MySQL. Those two ServerRuntimes are instantiated once in a singleton. The ObjectContexts are instantiated once per HTTP session and sent to the DAOs via ThreadLocal (This is very similar to the Cayenne's HTTP filter). Everything works well if I use directly objectContext.commitChanges() method to commit changes to DB. What I'm trying to do next is to use Cayenne Transactions using : Transaction tx = serverRuntime.getDataDomain().createTransaction(). .... tx.commit(); //or tx.rollback() depending on the situation The problem here is that if I do so, it means that if a user(or HTTP session) changes are committed, all other users(or HTTP sessions) changes will also be committed. This is because serverRuntime is a singleton and the transaction is created against it (and not against the objectContext which is bound to the HTTP session). I also took a look at the ServerRuntime source code and noticed that it defines two instance properties (injector and modules which are in the parent class: CayenneRuntime). If I'm not mistaken, this means that ServerRuntime is not a good candidate to be defined as a singleton (one instance per application). Maybe I'm not correctly using Cayenne to manage transaction when we have more than one server runtime. If so, what's the best way to achieve that please? Thanks --0015175cfbb039451e04bb6bf27f--