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

SpringManagedTransaction.openConnection() log. Could this be misunderstood? #1079

Open
cpcnjoker opened this issue Mar 20, 2025 · 0 comments

Comments

@cpcnjoker
Copy link

private void openConnection() throws SQLException {
    this.connection = DataSourceUtils.getConnection(this.dataSource);
    this.autoCommit = this.connection.getAutoCommit();
    this.isConnectionTransactional = DataSourceUtils.isConnectionTransactional(this.connection, this.dataSource);

    LOGGER.debug(() -> "JDBC Connection [" + this.connection + "] will"
        + (this.isConnectionTransactional ? " " : " not ") + "be managed by Spring");
  }

In the SpringManagedTransaction.openConnection() method, ‌if line 80 creates a new database connection‌, the conditional check at ‌line 81 will always evaluate to true‌. This occurs because the newly created connection is already stored in threadlocal storage during the preceding steps. As a result, ‌line 82 will log that the connection is "managed by Spring transactions"‌, even though this connection is actually ‌a fresh instance‌ created outside Spring's transactional context and remains ‌separate from the actual Spring-managed transactional connection‌.

version: 2.0.7

@cpcnjoker cpcnjoker changed the title SpringManagedTransaction.openConnection() log. Does it allow for equivocation? SpringManagedTransaction.openConnection() log. Could this be misunderstood? Mar 20, 2025
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

No branches or pull requests

1 participant