I have problem rolling back to a particular savepoint using Mybatis SqlSession instance. I do not have Spring framework in my web application. Hence I am manually rolling back the transactions whenever the second insertion fails.
private SqlSessionFactory sqlSessionFactory;
private MyRepositoryDAO()
{
sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory();
}
SqlSession session = sqlSessionFactory.openSession();
Savepoint savePointA = session.getConnection.setSavePoint();
if(insertionSuceeded)
{
session.commit();
}
else
{
session.rollback();
}
If(anotherInsertionSucceeded)
{
session.commit();
}
else
{
session.getConnection().rollback(savePointA)
}
If i run this piece of code i am getting this below error. com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: SAVEPOINT 688bd22f_1442b1b7a9c__8000 does not exist
Not sure what I am missing here. Thanks
In MySQL all transaction's savepoints are deleted when commit or rollback without savepoint is performed.
So if anotherInsertionSucceeded==false
transaction is first committed or rolled back and all savepoints are deleted and then rollback to savepoint fails.