0

I am using quarkus-narayana-jta for transaction management and using reactive MysqlPool to insert into db. MysqlPool class is not Autoclosable so do we need to explicitly call close() method from Pool class to close in case failure occurs or is it fine to just print the error message to the log and let transaction manager rollback the entire transaction in case failure occurs. What will be the impact if in case MySqlPool is not closed explicitly.

@Transactional
public Uni<String> insertIntoDb(BaseLog baseLog) {

    LocalDate currentDate = LocalDate.now();
    int year = currentDate.getYear();

    if (baseLog instanceof RequestLog) {
        prepareRequestLogData(baseLog, currentDate, year);
    }

    if (baseLog instanceof ResponseLog) {
        prepareResponseLogData(baseLog, currentDate, year);
    }

    return mysqlPool.preparedQuery(query).execute().onItem()
            .transformToUni(id -> mysqlPool
                    .query("SELECT TRAN_ID FROM " + tableName + " ORDER BY TO_DB_TS DESC LIMIT 1").execute())
            .onItem().transform(rows -> rows.iterator().next().getString(0)).onFailure().invoke(f -> {
                LOG.error("Error while inserting data to " + tableName + " table::" + f.getMessage());
            });

}
Pracheer Pancholi
  • 570
  • 2
  • 7
  • 21

1 Answers1

1

A Reactive SQL Pool does not integrate with @Transactional and a traditional TransactionManager such as Narayana.

If you use Reactive SQL you need to open/close the connections explicitly, and begin/end transactions explicitly.

If you're using Hibernate Reactive with Panache you can use @ReactiveTransactional.

Sanne
  • 6,027
  • 19
  • 34