Interface TransactionConcurrencyResolver

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface TransactionConcurrencyResolver

Determines the transaction concurrency behavior that Hibernate should assume for a session factory's connections. Called during bootstrap to produce an immutable TransactionConcurrency descriptor from dialect knowledge, available JDBC metadata, and an optional configuration declaration.

A resolver may combine three sources of database behavior:

  • Hard-coded dialect knowledge, when behavior is fixed for the database and version represented by the dialect. Such facts require no JDBC access.
  • Database-specific queries, when JDBC access is permitted, to discover settings which affect concurrency, such as SQL Server's READ_COMMITTED_SNAPSHOT setting.
  • The connection's configured isolation level, obtained using Connection.getTransactionIsolation(). Bootstrap exposes this observation through JdbcMetadata.getTransactionIsolation() when JDBC metadata is available, so the resolver need not read it again. A resolver may also inspect the supplied connection directly when JDBC access is permitted.

These sources are complementary, not a required sequence of attempts. A JDBC isolation value must be interpreted using dialect knowledge and any relevant database settings; it does not by itself distinguish all locking and snapshot behavior. The database's default isolation level is not a substitute for the configured isolation of the factory's connections.

Resolution also takes place when bootstrap has no JDBC connection. In that case, the resolver uses the supplied metadata, established dialect facts, and the declaration. Missing information must remain unknown; it must not be interpreted as a guarantee.

When bootstrap supplies a connection and JDBC access is permitted, the resolver may query it for additional facts, such as database settings that affect the behavior of the configured isolation level. The connection is borrowed only for the duration of resolve(Dialect, JdbcMetadata, Connection, Object, JdbcMetadataOnBoot). Implementations must not acquire another connection, retain or close the supplied connection, or change its isolation or other settings. Statements and result sets created by the resolver must be closed before returning.

The resulting descriptor describes behavior; it does not configure connections or track transactions in individual sessions. A named declaration may supply facts unavailable to bootstrap, but must not override known contradictory observations or dialect facts. A supplied descriptor is authoritative: bootstrap uses it directly without invoking this resolver. Built-in resolvers also return descriptor instances unchanged if called directly.

Since:
8.0
See Also:
  • Method Details

    • resolve

      TransactionConcurrency resolve(Dialect dialect, JdbcMetadata metadata, Connection connection, Object declaration, JdbcMetadataOnBoot access)

      Builds the factory's concurrency descriptor from the available facts. JDBC queries are permitted only when connection is non-null and access is not JdbcMetadataOnBoot.DISALLOW.

      A fact for which no probe is supported may remain unknown. If a supported probe fails under JdbcMetadataOnBoot.ALLOW, resolution may continue using the other available facts. Under JdbcMetadataOnBoot.REQUIRE, such a failure must fail resolution. Invalid names and known contradictions must fail resolution regardless of the access policy.

      Parameters:
      dialect - the resolved database dialect
      metadata - bootstrap metadata, which may contain no JDBC observations
      connection - the connection already obtained by bootstrap, or null when resolving without a connection
      declaration - the value of TransactionSettings.TRANSACTION_CONCURRENCY, either a name recognized by the resolver (the standard names are listed on that setting), or null if no baseline was declared. Direct calls supplying a TransactionConcurrency instance must return that instance without probing or validation
      access - the JDBC access policy for this resolution
      Returns:
      an immutable descriptor, independent of the supplied connection
      Throws:
      TransactionConcurrencyResolutionException - if a declaration is invalid, contradicts known facts, or a supported probe fails when JDBC access is required; these failures must not be hidden by bootstrap fallback