首页 > 解决方案 > Quarkus:回滚哪些异常?

问题描述

我认为 @Transaction 中的 RuntimeExceptions 不会导致还原和检查异常。

例如我有两个类:

A:

@POST
@Path( DO_SOMETHING )
@Consumes( MediaType.APPLICATION_JSON )
@Produces( { MediaType.APPLICATION_JSON } )
@Authenticated
public RestResponse doSomething( SetttingsDTO settings ) {
    Response eok = new Response();

    try {
        b.callMe( settings );

        eok.setResponse( "Successfull", null );
    } catch ( Exception ex ) {
        log.error( ex.getMessage() );
        eok.setResponse( ex );
    }

    return eok;
}

B类:

@Transactional
public void callMe( SetttingsDTO settings ) throws Exception {
    /*
    Here we do some things in the database
    */
    throw new IOException("Test");
}

据我了解,因为在 A 类中抛出并捕获了 IOException,所以数据库不应返回数据库更改。但实际上数据库确实恢复了。尽管捕获了异常,但我的数据库更改已写入数据库。

有人可以解释为什么吗?

标签: quarkus

解决方案


推荐阅读