Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HikariProxyConnection directly calls delegate.getTransactionIsolation(), causing a network call every time. #2198

Open
tacascer opened this issue May 8, 2024 · 1 comment · May be fixed by #2199

Comments

@tacascer
Copy link

tacascer commented May 8, 2024

Version: Hibernate 5.1

What

HikariProxyConnection.getTransactionIsolation() causes a network call everytime due to invoking delegate.getTransactionIsolation()

The method for HikariProxyConnection says:

public int getTransactionIsolation() throws SQLException {
  try {
    return super.delegate.getTransactionIsolation();
  } catch (SQLException var2) {
     throw this.checkException(var2);
  }

This causes a call to the underlying Connection.getTransactionIsolation(), which is usually a network call to the database.

Curiously, in ProxyConnection there is a similarly named method

final int getTransactionIsolationState()
{
return transactionIsolation;
}

Which returns the cached transaction isolation level stored by Hikari.

Why is this a problem

Example: In Spring, there is a check to see if the isolation level of the transaction matches that of the connection.
https://github.com/spring-projects/spring-framework/blob/8137cc95669690f3e4055d6ccf484e98a07b6703/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java#L208-L218

Thank you for your valuable time and attention!

@quaff
Copy link
Contributor

quaff commented May 9, 2024

Which returns the cached transaction isolation level stored by Hikari.

The cached transaction isolation only available if Connection::setTransactionIsolation called, I think it could be improved here, but the network call cannot be avoided if Connection::setTransactionIsolation not called first.

public void setTransactionIsolation(int level) throws SQLException
{
delegate.setTransactionIsolation(level);
transactionIsolation = level;
dirtyBits |= DIRTY_BIT_ISOLATION;
}

quaff added a commit to quaff/HikariCP that referenced this issue May 9, 2024
@quaff quaff linked a pull request May 9, 2024 that will close this issue
quaff added a commit to quaff/HikariCP that referenced this issue May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants