Search code examples
javatransactionsjdbi

Transaction Propagation in JDBI


I am using JDBI at the data layer, it doesn't use spring. In the project, I am calling a method which is marked with @Transaction from a method which itself is annotated with @Transaction.

@Transaction
public void updateEmployee(Employee employee) {
   employeeDao.update(employee);
   departmentDao.updateDepartment(employee.getDepartment())
} 

@Transaction
public void updateDepartment(Department department) {
  ...
}

I know how Spring's @transaction propagation works, but how does it work in the case of JDBI? what is the default propagation level? How to change it if needed?

As suggested in the docs https://jdbi.org/#_transactions we can manage transactions programmatically. But would like to know behavior in the annotation-based configuration.


Solution

  • In JDBI, there is no concept of REQUIRED_NEW. Both the calls would run in a same transaction,

    The below text is from the JDBI mailing group:

    There's no concept of parking a transaction and starting a separate inner transaction automatically at this time, although of course, it's straightforward enough to do so manually with two Handles.

    https://groups.google.com/d/msgid/jdbi/CAHjY6CVkSN%2BJ_KpEG_T1NXf%2B%2BwwOK7GxXz72ofs%2Bf_wONmL_Rw%40mail.gmail.com.