ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Clinton Begin <clinton.be...@gmail.com>
Subject Re: Why are creates auto-committing?
Date Wed, 22 Dec 2004 15:17:21 GMT
Which RDBMS are you using?


On Tue, 21 Dec 2004 15:57:07 -0600, Albert L. Sapp <asapp@uiuc.edu> wrote:
>  I am new to ibatis and using DAO and sqlMaps.  I am trying to perform
> multiple creates in a function and having them rollback if one of them
> fails.  The rollback does not seem to be performed.  Instead the creates up
> to that point are committed.  I apparently am not clear on what controls the
> commitment or rollback of multiple creates.  Here is the section of code
> from my program.  I am hoping that you can point out to me what I am doing
> wrong.
> 
>                  try
>                  {
>                          //Everything checks out, so add the new unit.
>                          logger.finer("Starting transaction.");
>                          startTransaction();
> 
>                          logger.finer("Creating unit manager role.");
>                          roleDAO.create(namedUnitManagerRole);
>                                          
>                          logger.finer("Creating unit staff role.");
>                          roleDAO.create(namedUnitStaffRole);
>                                          
>                          logger.finer("Creating unit manager user.");
>                          userDAO.create(manager);
> 
>                          logger.finer("Granting unit manager role to
> user.");
>                          userRoleDAO.create(userRole);
>                                          
>                          logger.finer("Creating Unit.");
>                          unitDAO.create(newUnit);
> 
>                          logger.finest("Create unit/unit type
> cross-references.");
>                          for ( int i = 0; i < unitToTypes.length; i++)
>                          {
>                                  UnitToType newUnitToType = new
> UnitToType();
>                                  newUnitToType = (UnitToType)unitToTypes[i];
>                          
>                                  unitToTypeDAO.create(newUnitToType);
>                                                  
>                                  logger.finest("Added UnitToType: " +
> newUnitToType);
>                                  
>                                  newUnitToType = null;
>                          }
>                          
>                          commitTransaction();
>                  }
>                  catch(DuplicatePK e)
>                  {
>                          try { endTransaction(); } catch (DaoException e1)
> {/*ignore*/}
>                          throw new ItemExists("This unit already
> exists.",e);
>                  }
>                  catch(DuplicateConstraint e)
>                  {
>                          try { endTransaction(); } catch (DaoException e1)
> {/*ignore*/}
>                          DuplicateDescription e1 = new
> DuplicateDescription("Duplicate unit data in another record.",e);
>                          e1.setFieldName(e.getFieldName());
>                          throw e1;
>                  }
>                  catch(NullConstraintViolation e)
>                  {
>                          try { endTransaction(); } catch (DaoException e1)
> {/*ignore*/}
>                          NullFields e1 = new NullFields("A unit field has
> been left empty that should not be empty.",e);
>                          e1.setFieldName(e.getFieldName());
>                          throw e1;
>                  }
>                  catch(DaoException e)
>                  {
>                          try { endTransaction(); } catch (DaoException e1)
> {/*ignore*/}
>                          throw new ManagerException("Dao Exception in trying
> to create new unit." + e.getCause(),e);
>                  }
>                  finally
>                  {
>                          endTransaction();
>                  }
> 
>  Thanks,
> 
>  Al Sapp

Mime
View raw message