Search code examples
javadatabasejdbi

JDBI Transactional .inTransaction() with void return type?


A JDBI Handle allows for transactions to be run via a call to .inTransaction(TransactionCallback<ReturnType> callback). This TransactionCallback may be a VoidTransactionCallback, which allows for a void return type.

I'm not seeing an equivalent when using a DAO that implements Transactional.

Transactional provides an inTransaction(Transaction<ReturnType,SelfType> func) method, where Transaction must have a return type. That return type can be Void, but is there another option I'm missing?


Solution

  • You're looking for useTransaction.

    The typical method pattern is withX for methods with a return type, and useX for void return--inTransaction being the only exception.