I've noticed something when doing some work on an improved executeBatch method.  If you don't include your batch in an explicit transaction, nothing will be executed.  For example, if I do this:
 
sqlMap.startBatch();
sqlMap.insert("someStatement", someObject);
sqlMap.insert("someStatement", anotherObject);
sqlMap.executeBatch();
 
Nothing get executed.  The reason is that each insert method clears out the session (and the associated batch) when it executes because it is assuming an implicit transaction.  So when the executeBatch() method executes there is no batch in the session.  If I do this:
 
sqlMap.startTransaction();
sqlMap.startBatch();
sqlMap.insert("someStatement", someObject);
sqlMap.insert("someStatement", anotherObject);
sqlMap.executeBatch();
sqlMap.commitTransaction();
 
Then everything is OK.
 
Question - is this the intended way this should work?  Or, is this an unintended side effect of the relatively new implicit transaction support?
 
If this is intended, then we need to change the documentation because it is wrong.  If it's unintended, then we need to fix the code.
 
Comments?
 
Jeff Butler
 

Reply via email to