Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 9892 invoked from network); 10 Jun 2006 01:13:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 10 Jun 2006 01:13:48 -0000 Received: (qmail 38490 invoked by uid 500); 10 Jun 2006 01:13:47 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 38470 invoked by uid 500); 10 Jun 2006 01:13:46 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 38459 invoked by uid 99); 10 Jun 2006 01:13:46 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Jun 2006 18:13:46 -0700 X-ASF-Spam-Status: No, hits=0.3 required=10.0 tests=HTML_MESSAGE,MAILTO_TO_SPAM_ADDR,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of ericblue76@gmail.com designates 64.233.166.179 as permitted sender) Received: from [64.233.166.179] (HELO py-out-1112.google.com) (64.233.166.179) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Jun 2006 18:13:45 -0700 Received: by py-out-1112.google.com with SMTP id f25so908602pyf for ; Fri, 09 Jun 2006 18:13:25 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=tN3Ov6PGtbxKIziV5KieuXuPonnOUX/eBF08z/90rjO9zlnKndPuzBduKeOhtZBudysEvkX7n2XpfcfsktO/FycuSNcKX3tN45gX0Ntg9SOxuCw3QVUODmiEnpJDgIjfPDmDRvvm3JS9SINUGRocakkbBnyTXAWTTdg9l20IxPI= Received: by 10.35.121.2 with SMTP id y2mr453872pym; Fri, 09 Jun 2006 18:13:25 -0700 (PDT) Received: by 10.35.31.12 with HTTP; Fri, 9 Jun 2006 18:13:25 -0700 (PDT) Message-ID: <295517f10606091813h147ff079pd5c699f084fc8d43@mail.gmail.com> Date: Fri, 9 Jun 2006 18:13:25 -0700 From: "Eric T. Blue" To: user-java@ibatis.apache.org Subject: Re: Help with understanding transaction behavior with multiple threads In-Reply-To: <295517f10606051637y782b31fbr9b83a058ea62ff4d@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_12902_24979478.1149902005086" References: <295517f10606051637y782b31fbr9b83a058ea62ff4d@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N ------=_Part_12902_24979478.1149902005086 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline No takers on this one? On 6/5/06, Eric T. Blue wrote: > > Hi, > > I want to find out the easiest possible way to start a transaction, create > a thread that performs DAO inserts, and still have the newly created thread > honor the start and end transaction from the launching application. > > I'm working on a project where I'm using iBatis DAO with SQLMAP as my > transaction manager. Up until this point transactions and rollbacks work > fine. > > daoManager.startTransaction(); > > try { > service.createObject (a); > > daoManager.commitTransaction(); > > } catch (ServiceException e) { > // Handle exception > } finally { > > daoManager.endTransaction(); > } > > I now have a situation where instead of calling service.createObject() > directly I'm creating an encapsulated unit of work and running with a new > thread. What I've discovered is that whenever an exception is thrown, the > create Object exists in the database, although commitTransaction has never > been called. After browsing through the mailing list, and eventually the > code, I discovered that the dao manager (DaoContext) is using ThreadLocal to > keep track of transaction and state. Given this fact, is it even possible > to solve my problem without having to change the underlying code or right > some sort of wrapper class. > > What I'm a little confused about is that default autocommit is set to > false. If the launched thread performs the INSERT, even though it is > unaware that start transaction and end transaction are happening, why is the > record being committed? Any help would be appreciated. > ------=_Part_12902_24979478.1149902005086 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline No takers on this one?


On 6/5/06, Eric T. Blue <ericblue76@gmail.com> wrote:
Hi,

I want to find out the easiest possible way to start a transaction, create a thread that performs DAO inserts, and still have the newly created thread honor the start and end transaction from the launching application.

I'm working on a project where I'm using iBatis DAO with SQLMAP as my transaction manager.  Up until this point transactions and rollbacks work fine.

daoManager.startTransaction();

try {
    service.createObject (a);
   
    daoManager.commitTransaction();

} catch (ServiceException e) {
    // Handle exception
} finally {

    daoManager.endTransaction();


I now have a situation where instead of calling service.createObject() directly I'm creating an encapsulated unit of work and running with a new thread.  What I've discovered is that whenever an exception is thrown, the create Object exists in the database, although commitTransaction has never been called.  After browsing through the mailing list, and eventually the code, I discovered that the dao manager (DaoContext) is using ThreadLocal to keep track of transaction and state.  Given this fact, is it even possible to solve my problem without having to change the underlying code or right some sort of wrapper class.

What I'm a little confused about is that default autocommit is set to false.  If the launched thread performs the INSERT, even though it is unaware that start transaction and end transaction are happening, why is the record being committed?  Any help would be appreciated.

------=_Part_12902_24979478.1149902005086--