Retrieve inserted id in mass insert using SqlMapExecutor.
Hello,
My environtment is:
Java 1.6
iBatis 2.3.4
Spring 2.5.6
MySQL
I've a method to create records massively (I write directly, it can has sintax errors; just take the idea):
public List<T> createRecordsMassively(final List<T> records) {
getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
executor.startBatch();
for (T record : records) {
executor.insert("insertRecord", record);
}
//List<BatchResult> result = executor.executeBatchDetailed();
int rowsAffected = executor.executeBatch();
return new Integer(rowsAffected);
}
});
/*Deal with result*/
}
It works well. Assume that insertRecord also works well (in a single insert, it retrieve the Id correctly using <selectKey keyProperty="id" resultClass="long" type="post">). The problem is: I want to know which records are correctly inserted and which aren't. I need the Id in order to execute some logic with each inserted record. 'executeBatchDetailed' doesn't return the inserted objects with the Id.
¿What's the way? ¿How can I retrieve the id of the inserted records?
Thanks in advance,
Westhveg