HikariCP behavior on connection close if transaction was not explicitly committed/rolled-back?

Viewed 1288

I am migrating from BoneCP to HikariCP. In BoneCP there is the following option:

# If true, issue a reset (rollback) on connection close in case client forgot it.
resetConnectionOnClose=true

What is HikariCP's behavior in this scenario, when the connection is closed without explicitly committing/rolling-back the transaction? I did not find the equivalent configuration option.

Thank you, Gab

2 Answers

I found my answer in com.zaxxer.hikari.pool.ProxyConnection's code source. In the close() method there is the following code:

if (this.isCommitStateDirty && !this.isAutoCommit) {
    this.delegate.rollback();
    this.lastAccess = ClockSource.currentTime();
    LOGGER.debug("{} - Executed rollback on connection {} due to dirty commit state on close().", this.poolEntry.getPoolName(), this.delegate);
}

thus if you do not have the autoCommit config option enabled and you did not explicitly commit/rollback then it rollsback for you.

I didn't check but basically HikariPool call close method for Connection so it seems to be depending on the driver implementation

It is strongly recommended that an application explicitly commits or rolls back an active transaction prior to calling the close method. If the close method is called and there is an active transaction, the results are implementation-defined.

Related