Results 1 to 2 of 2

Thread: SqlMapClientDaoSupport batch update problem (iBatis).

  1. #1
    Join Date
    Aug 2004
    Location
    Vancouver, Canada
    Posts
    25

    Default SqlMapClientDaoSupport batch update problem (iBatis).

    I'm using iBatis SqlMapClientDaoSupport for my DAO.

    Code:
        public void batchInsertCustomer( final List customerList ) 
        {
        	
        	getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
    
    			public Object doInSqlMapClient(SqlMapExecutor executor)
    					throws SQLException {
    				
    				executor.startBatch();
    				
    				for &#40;int i = 0; i < customerList.size&#40;&#41;; i++&#41; &#123;
    					executor.update&#40;"insertCustomerWithoutKey", customerList.get&#40;i&#41;&#41;;
    				&#125;
    
    				int updCount = executor.executeBatch&#40;&#41;;
    	            return null;
    			&#125;
    
        	&#125;&#41;;
        &#125;
    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.

    Ram.

  2. #2
    Join Date
    Aug 2004
    Location
    Vancouver, Canada
    Posts
    25

    Default

    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.

Similar Threads

  1. Replies: 7
    Last Post: Nov 6th, 2008, 10:28 AM
  2. batch update error using Hibernate 3
    By sbmahs in forum Data
    Replies: 1
    Last Post: Jun 17th, 2006, 01:02 PM
  3. Replies: 9
    Last Post: Jun 10th, 2005, 07:19 AM
  4. Replies: 1
    Last Post: Apr 29th, 2005, 05:39 PM
  5. Ibatis update issue
    By biggs in forum Data
    Replies: 0
    Last Post: Feb 2nd, 2005, 04:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •