Hi
Camel 2.10 version:
When the onCosume , sql hits error , instead of rolling back, the
transaction gets committed. This results in unwarranted transaction
integrity issues. if you multiple comma separted statements, if the error is
hit , the earlier statement partial updates are committed.
Worst there is no error thrown back, so the routes do not know what's going
on
Looking at the MyBatis component source code:
DefaultMyBatisProcessingStrategy
The root cause there is a session.commit on finally block
public void commit(MyBatisEndpoint endpoint, Exchange exchange, Object data,
String consumeStatements) throws Exception {
SqlSession session = endpoint.getSqlSessionFactory().openSession();
String[] statements = consumeStatements.split(",");
try {
for (String statement : statements) {
session.update(statement.trim(), data);
}
} finally {
session.commit();
session.close();
}
}
Suggested Fix:(Move the commit after successful updates in try block.
Rollback any updates in catch block. finally just closes the session. It
will also automatically throws back the error)
public void commit(MyBatisEndpoint endpoint, Exchange exchange, Object data,
String consumeStatements) throws Exception {
SqlSession session = endpoint.getSqlSessionFactory().openSession();
String[] statements = consumeStatements.split(",");
try {
for (String statement : statements) {
session.update(statement.trim(), data);
}
session.commit(); // CHANGE: COMMIT IF ALL ARE SUCCESSFUL
} catch{
session.rollback(); // ANY ERROR, ROLLBACK INTERMEDIATE
TRANSACTION CHANGES
}
} finally {
session.close();
}
}
--
View this message in context:
http://camel.465427.n5.nabble.com/MyBatis-Component-Bug-consumer-onConsume-hits-error-transactions-are-committed-instead-of-rollback-tp5716774.html
Sent from the Camel - Users mailing list archive at Nabble.com.