ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Abhigyan Agrawal1 <abhigyan_agra...@in.ibm.com>
Subject Re: Question about the executeBatch......
Date Wed, 22 Apr 2009 11:22:23 GMT
Please reply to the community (user-java@ibatis.apache.org) 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 <mrlvxy@gmail.com> 
22/04/2009 13:26

To
Abhigyan Agrawal1/India/IBM@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 <abhigyan_agrawal@in.ibm.com>

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 <mrlvxy@gmail.com> 
22/04/2009 11:10 


Please respond to
user-java@ibatis.apache.org


To
user-java@ibatis.apache.org 
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


Mime
View raw message