Please reply to the community ([email protected]) instead of individual mail ids. Did the values got updated in database? You need to ensure that the parent function which is calling CardDao and SubscriberDao is under one transaction. Then it should work.
Thanks, Abhigyan Joey Lv <[email protected]> 22/04/2009 13:26 To Abhigyan Agrawal1/India/i...@ibmin cc Subject Re: Question about the executeBatch...... Hi Abhigyan, Thanks for your reply. I tested it following your suggestion, but I still got null. In fact, I have a CardService, it will invoke two Dao, one is CardDao, the other is SubscriberDao. The CardDao will insert some records into DB, and the SubscriberDao will update some records into DB, and the Spring will manage the whole transaction. So, how can I do? Thanks Joey 2009/4/22 Abhigyan Agrawal1 <[email protected]> Hi Joey, You should always put a batch inside an explicit transaction, otherwise iBATIS will execute each statement individually. (i.e. it will ignore batch completely). That's why batchResult is empty. If you look at your database, all the updates would have happened. Try: this.getSqlMapClient().startTransaction(); this.getSqlMapClient().startBatch(); for (Subscriber subscriber : subscriberList) { this.getSqlMapClient().update("Subscriber_updateSubscriber", subscriber); } List<BatchResult> batchResult = this.getSqlMapClient().executeBatchDetailed(); this.getSqlMapClient().commitTransaction(); Now you should see desired result. P.S.- setInBatch(false) used in executeBatchDetailed() shouldn't affect executeBatchDetailed at all. Thanks, Abhigyan Joey Lv <[email protected]> 22/04/2009 11:10 Please respond to [email protected] To [email protected] cc Subject Question about the executeBatch...... Hi, Below is my java code, to execute a batch this.getSqlMapClient().startBatch(); for (Subscriber subscriber : subscriberList) { this.getSqlMapClient().update("Subscriber_updateSubscriber", subscriber); } List<BatchResult> batchResult = this.getSqlMapClient().executeBatchDetailed(); But I found the batchResult alway is null. Here is the source code of com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate#startBatch public void startBatch(SessionScope session) { session.setInBatch(true); } and here is the source code of com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate#executeBatchDetailed public List executeBatchDetailed(SessionScope session) throws SQLException, BatchException { session.setInBatch(false); return sqlExecutor.executeBatchDetailed(session); } So, why need ‘session.setInBatch(false);’ in the mehod executeBatchDetailed()? And is this the cause of "batchResult always is null"? Thanks Joey Lv -- Long Young Plastics (ShenZhen) Ltd (Product: Vinyl Fence, PVC, ABS) http://www.longyoungplast.com
