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?


Reply via email to