0

我不明白为什么抛出运行时异常时调用after()函数。DBConnectionFilter我期待onException()调用函数并回滚事务。但真正发生的是该after()函数将被调用以提交事务并关闭数据库连接,然后 onException调用来自 CatchAllFilter/kind of global filter/ 的该函数。

AppControllerConfig 类:

public class AppControllerConfig extends AbstractControllerConfig{

    public void init(AppContext context) {
        add(new CatchAllFilter(), new DBConnectionFilter("default",true));
    }
}

PeopleController 创建函数:

@POST
public void create() throws IOException {
    String incomingPost = Util.read(getRequestInputStream());

    Map[] people = JsonHelper.toMaps(incomingPost);
    Person newPerson = new Person();
    newPerson.fromMap(people[0]);
    boolean response = newPerson.save();

    //Making sure person info is persisted so that it can be Rolled back   
    if (response == true) {
        throw new InitException("Rollback Transaction");
    }
    render("/system/RestIndex").noLayout().contentType("application/json");
    view("jsonResponse", Person.findAll().toJson(true));

}
4

1 回答 1

0

因此,查看 ActiveWeb 的代码,我可以看到事务首先被回滚,然后被提交。我假设一旦事务回滚,驱动程序将丢弃尚未提交的数据,但在我的测试中 MariaDB/MySQL 并没有发生这种情况。换句话说,我用一个简单的 ActiveWeb 项目在我的笔记本电脑上复制了这个问题。因此,此错误已提交:https ://github.com/javalite/activeweb/issues/389并已修复。您可以从http://repo.javalite.io/org/javalite/activeweb/拉出一个新的 2.1-SNAPSHOT 版本,它应该可以工作。

于 2018-07-27T21:12:18.257 回答