You don't even have to really... it will be called automatically if you don't call commit in most cases. Write a unit test for yourself to confirm this in your environment.
But yes, what you wrote looks fine. My only recommendation would be to roll back regardless of the exception type (e.g. catch Throwable) Cheers, Clinton On Sun, Mar 28, 2010 at 3:13 AM, 陈抒 <csfreeb...@gmail.com> wrote: > Hello: > My transactionManager type is JDBC. There is a sample in IBatis3 > document: > > SqlSession session = sqlSessionFactory.openSession(); > try { > // following 3 lines pseudocod for “doing some work” > session.insert(...); > session.update(...); > session.delete(...); > session.commit(); > } finally { > session.close(); > } > > If an insert statement failed caused by duplicated key,can I catch > SQLException and call session.rollback()?Like so: > SqlSession session = sqlSessionFactory.openSession(); > try { > // following 3 lines pseudocod for “doing some work” > session.insert(...); > session.update(...); > session.delete(...); > session.commit(); > }catch(SQLException ex){ > session.rollback(); > } finally { > session.close(); > } > I don't want to use any frameworks. > > > 陈抒 > Best regards > http://blog.csdn.net/sheismylife >