[英]Jdbi3: transaction with more than one dao and @Transaction annotation
I have to execute a transactions that involves methods in more than one dao, so I am using something like:我必须执行一个涉及多个 dao 中的方法的事务,所以我使用的是类似的东西:
jdbi.useHandle(handle -> {
handle.useTransaction(h -> {
Dao1 dao1 = h.attach(Dao1.class);
Dao2 dao2 = h.attach(Dao2.class);
dao1.method1();
dao2.method2();
});
});
but if for example in Dao1
method1 is annotated with @Transaction
, like:但如果例如在
Dao1
中,method1 用@Transaction
注释,例如:
public interface Dao1 {
@SqlUpdate
@Transaction
public void method1();
}
The above handle parts will execute both the methods in the same transaction?上面的句柄部分会在同一个事务中执行这两种方法吗? Or method1 will open a new transaction during execution?
还是method1会在执行过程中开启一个新事务?
Do not use @Transaction annotation if you want to reuse DAO methods in another transaction.如果您想在另一个事务中重用 DAO 方法,请不要使用 @Transaction 注释。 This makes slow performance and complicated checkpoints for rollbacks, if DBMS can support, it causes exceptions.
这会导致性能下降和回滚检查点复杂,如果 DBMS 可以支持,则会导致异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.