You need to wrap the batch in a transaction....

try {
  sqlMapClient.startTransaction();
  sqlMapClient.startBatch();
  ...
  sqlMapClient.executeBatch();
  sqlMapClient.commitTransaction();
} finally {
  sqlMapClient.endTransaction
}

Clinton

On 10/18/05, Gary Barlow <[EMAIL PROTECTED]> wrote:
Hi there, I'm using v2.1.5 with spring and attempting to use batched
statements but it doesn't seem to batch! The code below functions fine but
when testing for duplicate inserts I noticed if failed on the insert rather
than the executeBatch() statement. This suggests it's not batching! Also
noticed that the count returned from execute batch is always zero.

Have I coded this corrrectly? Are there any know issues?

public class SqlMapParameterDao extends SqlMapClientDaoSupport implements
ParameterDao {

............................

public void saveParameterValues(final Parameter parameter, final List vals)
throws IntegrityViolationException {
try {

this.getSqlMapClient().startBatch();
for (int i = 0; i < pvals.size(); i++) {
ParameterValue parameterValue = (ParameterValue) pvals.get(i);
this.getSqlMapClient().insert("insertParameterValue", new
ParameterValueCriteria(parameterValue.getParameter ().getId(),
parameterValue));
}
int count = this.getSqlMapClient().executeBatch();
} catch (SQLException e) {
throw new IntegrityViolationException(e.getMessage());
}
}



Reply via email to