Return-Path: Delivered-To: apmail-incubator-ibatis-user-java-archive@www.apache.org Received: (qmail 27591 invoked from network); 24 May 2005 19:40:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 24 May 2005 19:40:20 -0000 Received: (qmail 69315 invoked by uid 500); 24 May 2005 19:40:19 -0000 Delivered-To: apmail-incubator-ibatis-user-java-archive@incubator.apache.org Received: (qmail 69293 invoked by uid 500); 24 May 2005 19:40:19 -0000 Mailing-List: contact ibatis-user-java-help@incubator.apache.org; run by ezmlm Precedence: bulk Reply-To: ibatis-user-java@incubator.apache.org List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list ibatis-user-java@incubator.apache.org Received: (qmail 69280 invoked by uid 99); 24 May 2005 19:40:19 -0000 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=DNS_FROM_RFC_ABUSE,HTML_40_50,HTML_MESSAGE,RCVD_BY_IP,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of clinton.begin@gmail.com designates 64.233.184.192 as permitted sender) Received: from wproxy.gmail.com (HELO wproxy.gmail.com) (64.233.184.192) by apache.org (qpsmtpd/0.28) with ESMTP; Tue, 24 May 2005 12:40:16 -0700 Received: by wproxy.gmail.com with SMTP id 69so2465440wra for ; Tue, 24 May 2005 12:40:04 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:references; b=IZXgM3mYkS0Inj3ItDk/4XnpghUZZws0S+yAqeYP3c2CE24coFXmha805g/m6oHsTU6ECmc7XGEnG/0e4PYjz3bb0FmDujUfqM4j5mWmv5Y8yUbMOtsuEtv2iL698xvyu89SdEC4mDBNItM3pDyp30bhdzPOpKdOWjI06b3vjtY= Received: by 10.54.107.4 with SMTP id f4mr4432928wrc; Tue, 24 May 2005 12:40:04 -0700 (PDT) Received: by 10.54.93.11 with HTTP; Tue, 24 May 2005 12:40:04 -0700 (PDT) Message-ID: <16178eb1050524124032c055d2@mail.gmail.com> Date: Tue, 24 May 2005 13:40:04 -0600 From: Clinton Begin Reply-To: cbegin@ibatis.com To: ibatis-user-java@incubator.apache.org, Brandon Goodin Subject: Re: transactions In-Reply-To: <2fe5ef5b050524123742745b7d@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_24381_1635840.1116963604702" References: <2fe5ef5b05052411451f3a090b@mail.gmail.com> <2fe5ef5b050524123742745b7d@mail.gmail.com> X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N ------=_Part_24381_1635840.1116963604702 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Those update statements ARE in a transaction. But you should NEVER manage= =20 transactions inside the DAO. The transaction in this case is taken care of= =20 outside of the scope of this particular method (I believe in this case it i= s=20 actually an automatic DAO transaction, so you might not find the calls to= =20 start/commit/end).=20 Clinton On 5/24/05, Brandon Goodin wrote: >=20 > Message was sent to me privately... so i am posting it to the list > ----- > But for example, in the JPetStoreExample, in the AccountSqlMapDao, this i= s=20 > a > method: >=20 > public void insertAccount(Account account) { > update("insertAccount", account); > update("insertProfile", account); > update("insertSignon", account); > } >=20 > Aren't those different update statements better off in a transaction? And > why no different calls from the Service layer? > I'm just trying to understand the difference. >=20 > >From: Brandon Goodin > >Reply-To: Brandon Goodin > >To: ibatis-user-java@incubator.apache.org > >Subject: Re: transactions > >Date: Tue, 24 May 2005 12:45:59 -0600 > > > >It is not neccessary to call transactions on only one statement. > > > >Transactions should be handled on the Service layer and make more > >fine-grained calls to the DAO layer. > > > >Brandon > > > >On 5/24/05, Lieven De Keyzer wrote: > > > At http://www.reumann.net/struts/ibatisLesson1/step6.do > > > this is an example in a ibatis/struts tutorial > > > > > > public int update(String statementName, Object parameterObject) throw= s > > > DaoException { > > > int result =3D 0; > > > try { > > > sqlMap.startTransaction(); > > > result =3D sqlMap.executeUpdate(statementName, parameterObject); > > > sqlMap.commitTransaction(); > > > } catch (SQLException e) { > > > try { > > > sqlMap.rollbackTransaction(); > > > } catch (SQLException ex) { > > > throw new DaoException(ex.fillInStackTrace()); > > > } > > > throw new DaoException(e.fillInStackTrace()); > > > } > > > return result; > > > } > > > > > > Is it necessary to have a transaction started for just 1 statement > > > execution? > > > > > > Also, what's the better way? Doing a transaction in a Service class, > >that > > > has multiple DAO's, or doing it in the DAO class, doing different > >statements > > > in one method? Or is there no difference? > > > > > > > > > > ------=_Part_24381_1635840.1116963604702 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Those update statements ARE in a transaction. But you should NEVER manage transactions inside the DAO.  The transaction in this case is taken care of outside of the scope of this particular method (I believe in this case it is actually an automatic DAO transaction, so you might not find the calls to start/commit/end).

Clinton

On 5/24/05, Brandon Goodin <brandon.goodin@gmail.com> wrote:
Message was sent to me privately... so i am posting it to the list
-----=
But for example, in the JPetStoreExample, in the AccountSqlMapDao, this= is a
method:

  public void insertAccount(Account accou= nt) {
    update("insertAccount", account);
&nbs= p;   update("insertProfile", account);
 &n= bsp;  update("insertSignon", account);
  }=

Aren't those different update statements better off in a transactio= n? And
why no different calls from the Service layer?
I'm just trying to un= derstand the difference.

>From: Brandon Goodin <brandon.goodin@gmail.com>
>Reply= -To: Brandon Goodin < brandon.goodin@gmail.com>= ;
>To: ibati= s-user-java@incubator.apache.org
>Subject: Re: transactions
&g= t;Date: Tue, 24 May 2005 12:45:59 -0600
>
>It is not neccessary to call transactions on only one state= ment.
>
>Transactions should be handled on the Service layer an= d make more
>fine-grained calls to the DAO layer.
>
>Bran= don
>
>On 5/24/05, Lieven De Keyzer <lieven_dekeyzer@hotmail.com> wrote:
> >= ; At  http://www.reumann.net/struts/ibatisLesson1/step6.do
> > this is an example in a ibatis/struts tutorial
> &g= t;
> > public int update(String statementName, Object parameterObj= ect) throws
> > DaoException {
> >    = ; int result =3D 0;
> >     try {
> >   &= nbsp;     sqlMap.startTransaction();
> > =         result =3D sqlMap.executeUpdate(= statementName, parameterObject);
> >     =     sqlMap.commitTransaction();
> >  &nbs= p;  } catch (SQLException e) {
> >         try {
>= >           &nbs= p; sqlMap.rollbackTransaction();
> >     =     } catch (SQLException ex) {
> >  &nbs= p;          throw new DaoExcep= tion(ex.fillInStackTrace());
> >     &nbs= p;   }
> >         throw new Dao= Exception(e.fillInStackTrace());
> >     }
= > >     return result;
> > }
> >= ;
> > Is it necessary to have a transaction started for just 1 sta= tement
> > execution?
> >
> > Also, what's the better = way? Doing a transaction in a Service class,
>that
> > has m= ultiple DAO's, or doing it in the DAO class, doing different
>stateme= nts
> > in one method? Or is there no difference?
> >
>= ; >
> >

------=_Part_24381_1635840.1116963604702--