Return-Path: Delivered-To: apmail-incubator-ibatis-user-java-archive@www.apache.org Received: (qmail 18194 invoked from network); 25 May 2005 02:57:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 25 May 2005 02:57:38 -0000 Received: (qmail 14669 invoked by uid 500); 25 May 2005 02:57:36 -0000 Delivered-To: apmail-incubator-ibatis-user-java-archive@incubator.apache.org Received: (qmail 14641 invoked by uid 500); 25 May 2005 02:57:36 -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 14627 invoked by uid 99); 25 May 2005 02:57:36 -0000 X-ASF-Spam-Status: No, hits=1.7 required=10.0 tests=DNS_FROM_RFC_ABUSE,DNS_FROM_RFC_POST,MSGID_FROM_MTA_HEADER,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of lieven_dekeyzer@hotmail.com designates 64.4.49.26 as permitted sender) Received: from bay14-f26.bay14.hotmail.com (HELO hotmail.com) (64.4.49.26) by apache.org (qpsmtpd/0.28) with ESMTP; Tue, 24 May 2005 19:57:33 -0700 Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Tue, 24 May 2005 19:57:31 -0700 Message-ID: Received: from 217.136.74.78 by by14fd.bay14.hotmail.msn.com with HTTP; Wed, 25 May 2005 02:57:30 GMT X-Originating-IP: [217.136.74.78] X-Originating-Email: [lieven_dekeyzer@hotmail.com] X-Sender: lieven_dekeyzer@hotmail.com From: "Lieven De Keyzer" To: ibatis-user-java@incubator.apache.org Bcc: Subject: Re: Transactions Date: Wed, 25 May 2005 02:57:30 +0000 Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-OriginalArrivalTime: 25 May 2005 02:57:31.0001 (UTC) FILETIME=[7E1C4690:01C560D5] X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Sorry to pick this up again, but I still have got one question. Wouldn't it be save to always wrap the calls in the service layer to the dao layer, in transactions? If this would be the case: accountDao.insertAccount(account); Dao Layer: public void insertAccount(Account account) { update("insertAccount", account); } There seems no need to use a startTransaction in the service layer, because only one statement is executed. But if the insertAccount method would change to: public void insertAccount(Account account) { update("insertAccount", account); update("insertProfile", account); update("insertSignon", account); } I would have to alter de Service layer code. I think it's a bit weird and violates the principles of OO. I guess I'm seeing this totally wrong? >I think we are getting in to splitting hairs here. The answer on where >to put it would have to reside in whether you will be >updating/inserting accounts from any other location and if it is a >requirement that everytime you update/insert an account that you also >update/insert a profile and a signon. There are probably a dozen other >reasons i could come up with that would influence where to put it. My >general rule on things like this is that I would push it up into the >Service layer regardless because insertAccount, insertProfile and >insertSignon are fine-grained calls that possible could be used >outside of this block. But, like i said above... that judgment may >change based on the "business rules". But, truly, i don't think there >is an easy "this way is right" approach. >Brandon >On 5/24/05, Jason Hall <[EMAIL PROTECTED]> wrote: >if a an error occurs in any of these 3 updates below > > > update("insertAccount", account); > > > update("insertProfile", account); > > > update("insertSignon", account); >a rollback will occur before the daoManager.commitTransaction(). >So isn't it safe to say that these updates a wrapped in the transaction? >Also doesn't this constitute a valid insert of Account? > >Example: > >Service Layer: > >doaManager.startTransaction(); >accountDao.insertAccount(account); >doaManager.commitTransaction(); >.... >finally(){doaManager.endTransaction():} > >Dao Layer: >public void insertAccount(Account account) >{ >update("insertAccount", account); >update("insertProfile", account); >update("insertSignon", account); >} > > > >-----Original Message----- >From: Lieven De Keyzer [mailto:[EMAIL PROTECTED] >Sent: Tuesday, May 24, 2005 3:48 PM >To: [EMAIL PROTECTED]; ibatis-user-java@incubator.apache.org; >[EMAIL PROTECTED] >Subject: Re: transactions > > > > > >From: Clinton Begin <[EMAIL PROTECTED]> > >Reply-To: [EMAIL PROTECTED] > >To: ibatis-user-java@incubator.apache.org, Brandon Goodin > ><[EMAIL PROTECTED]> > >Subject: Re: transactions > >Date: Tue, 24 May 2005 13:40:04 -0600 > > > >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 Ddo you have AO transaction, so you might not find >the >calls to > >start/commit/end). > >So, what you mean is: I should make the transaction in my service layer, >and >inside this transaction call the dao method. But if I change a method in my >DAO, to have multiple statements, I would also need to change my Service >class, to place the call in a transaction? >And how does one specify those automatic transactions? > > > >Clinton > > > >On 5/24/05, Brandon Goodin <[EMAIL PROTECTED]> 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 account) { > > > update("insertAccount", account); > > > update("insertProfile", account); > > > update("insertSignon", account); > > > } > > > > > > 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. > > > > > > >From: Brandon Goodin <[EMAIL PROTECTED]> > > > >Reply-To: Brandon Goodin <[EMAIL PROTECTED]> > > > >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 <[EMAIL PROTECTED]> 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) > >throws > > > > > DaoException { > > > > > int result = 0; > > > > > try { > > > > > sqlMap.startTransaction(); > > > > > result = 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? > > > > > > > > > > > > > > > > > > > > >