Skip to content

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

Open
@cpcnjoker

Description

@cpcnjoker
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions