Reputation: 3640
I have to execute a transactions that involves methods in more than one dao, so I am using something like:
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:
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?
Upvotes: 0
Views: 922
Reputation: 21
Do not use @Transaction annotation if you want to reuse DAO methods in another transaction. This makes slow performance and complicated checkpoints for rollbacks, if DBMS can support, it causes exceptions.
Upvotes: 1