Spring @Transactional annotation when using try catch block

前端 未结 4 1874
花落未央
花落未央 2020-12-13 13:46

If we catch the exception in method annotated with the @Transactional annotation, will it roll back if any exception occurs?

@Transactional(read         


        
4条回答
  •  北荒
    北荒 (楼主)
    2020-12-13 14:39

    you would want to read this

    Integrated transaction management. You can wrap your ORM code with a declarative, aspect-oriented programming (AOP) style method interceptor either through the @Transactional annotation or by explicitly configuring the transaction AOP advice in an XML configuration file. In both cases, transaction semantics and exception handling (rollback, and so on) are handled for you. As discussed below, in Resource and transaction management, you can also swap various transaction managers, without affecting your ORM-related code. For example, you can swap between local transactions and JTA, with the same full services (such as declarative transactions) available in both scenarios. Additionally, JDBC-related code can fully integrate transactionally with the code you use to do ORM. This is useful for data access that is not suitable for ORM, such as batch processing and BLOB streaming, which still need to share common transactions with ORM operations.

提交回复
热议问题