在 EJB 中,@TransactionAttribute(TransactionAttributeType.REQUIRED) 将如何提交我的 jdbc 事务?

In EJB how @TransactionAttribute(TransactionAttributeType.REQUIRED) will commit my jdbc transaction as well?

在 EJB 中,我发现有一个可用的注解,如 @TransactionAttribute(TransactionAttributeType.REQUIRED) ,因此事务将由容器本身管理。但是使用它,你不需要写 con.commit() 因为容器会处理它(我只是猜测,因为我是 EJB 的新手)。所以我的困惑是 jdbc 事务如何与容器事务相关联,它在具有注释 @TransactionAttribute(TransactionAttributeType.REQUIRED)

的方法末尾提交

简短的回答是肯定的,除非发生异常,在这种情况下事务将被回滚。 这是一个 容器管理事务 的示例。 另一个选项是 User Managed Transaction,其中事务的边界由 tx.begin()、tx.commit() 等定义。 对于大多数需求,容器管理事务就足够了。