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.
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_SNAPSHOTsetting. - The connection's configured isolation level, obtained using
Connection.getTransactionIsolation(). Bootstrap exposes this observation throughJdbcMetadata.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 Summary
Modifier and TypeMethodDescriptionresolve(Dialect dialect, JdbcMetadata metadata, Connection connection, Object declaration, JdbcMetadataOnBoot access) Builds the factory's concurrency descriptor from the available facts.
-
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
connectionis non-null andaccessis notJdbcMetadataOnBoot.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. UnderJdbcMetadataOnBoot.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 dialectmetadata- bootstrap metadata, which may contain no JDBC observationsconnection- the connection already obtained by bootstrap, ornullwhen resolving without a connectiondeclaration- the value ofTransactionSettings.TRANSACTION_CONCURRENCY, either a name recognized by the resolver (the standard names are listed on that setting), ornullif no baseline was declared. Direct calls supplying aTransactionConcurrencyinstance must return that instance without probing or validationaccess- 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
-