Announcement Announcement Module
No announcement yet.
SqlMapClientDaoSupport batch update problem (iBatis). Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • SqlMapClientDaoSupport batch update problem (iBatis).

    I'm using iBatis SqlMapClientDaoSupport for my DAO.

        public void batchInsertCustomer( final List customerList ) 
        	getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
    			public Object doInSqlMapClient(SqlMapExecutor executor)
    					throws SQLException {
    				for &#40;int i = 0; i < customerList.size&#40;&#41;; i++&#41; &#123;
    					executor.update&#40;"insertCustomerWithoutKey", customerList.get&#40;i&#41;&#41;;
    				int updCount = executor.executeBatch&#40;&#41;;
    	            return null;
    Even though i'm executing multiple updates within the batch, iBatis is internally doing a 'executeBatch' at the end of the first update. After this all other updates are executed without batch.

    iBatis is auto starting a transaction inside the update method and the end of the update it tries to commit the transaction....Since a batch is open, it executes the batch and also closes the batch. 'autostart' of the transaction seems to be the culprit.

    After looking though iBatis mailing lists, i found some references to startTransaction() call before startBatch(). Is this required ? And how do i do this with Spring SqlMapClientDaoSupport ?

    I'm already using the DataSourceTransactionManager and the transaction is active.

    Thanks for your help.


  • #2
    I had to add getSqlMapClient().startTransaction() call before the start batch call.

    Its odd that i have to call startTransaction explicitly even though a local transaction is already active ( using DataSourceTransactionManager).

    Is this how its supposed to work ? SqlMapClientTemplate javadoc doesn't include this in the sample.