1.问题发现
在controller中注入service,第一次通过XxxxService bookService = new XxxxService();注入Jfinal使用@Before(Tx.class)在service层开启事务时,测试总是不能成功回滚,
在controller层改变Service的注入方式:XxxxService courseService = enhance(XxxxService.class);成功回滚。
注意:config.java文件配置数据连接时要设置
arpLog.setTransactionLevel(Connection.TRANSACTION_REPEATABLE_READ);
arpLog.setTransactionLevel(Connection.TRANSACTION_REPEATABLE_READ);
2.回滚需手动添加
在catch代码块中添加
try {
DbKit.getConfig().getConnection().rollback();
} catch (SQLException e1) {
System.out.println("xx事务回滚失败,请检查数据库是否不支持事务");
e1.printStackTrace();
}