简体   繁体   中英

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:

    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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM