You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Joey Lv <mr...@gmail.com> on 2009/04/22 07:40:34 UTC
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
Re: Question about the executeBatch......
Posted by Abhigyan Agrawal1 <ab...@in.ibm.com>.
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 <mr...@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 <ab...@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 <mr...@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
Re: Question about the executeBatch......
Posted by Abhigyan Agrawal1 <ab...@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 <mr...@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