Interface SharedStatelessSessionBuilder

All Superinterfaces:
CommonBuilder, CommonSharedBuilder, StatelessSessionBuilder

@Incubating public interface SharedStatelessSessionBuilder extends StatelessSessionBuilder, CommonSharedBuilder
Allows creation of a child StatelessSession which shares some options with another pre-existing parent session.

A child stateless session does not, by default, share the parent's JDBC connection, transaction coordinator, interceptor, or SQL statement inspector. Instead, the child stateless session starts from the normal SessionFactory defaults, with the parent's tenant identifier and JDBC time zone inherited as the baseline. The parent's interceptor, SQL statement inspector, connection, and transaction context are inherited only when explicitly requested by calling interceptor(), statementInspector(), or connection().

When resource-local transaction management is used:

  • by default, each session executes with its own dedicated JDBC connection and therefore has its own isolated transaction, but
  • calling the connection() method specifies that the connection, and therefore also the JDBC transaction, should be shared from parent to child.
A child stateless session with a shared transaction context also receives parent flush and close notifications, so its JDBC batch is executed with the parent, and the child is automatically closed when the parent is closed.
try (var statelessSession
         = session.statelessWithOptions()
                 .connection() // share the JDBC connection
                 .cacheMode(CacheMode.IGNORE)
                 .openStatelessSession()) {
    ...
}
On the other hand, when JTA transaction management is used, all sessions execute within the same transaction. Typically, connection sharing is handled automatically by the JTA-enabled DataSource.
Since:
7.2
See Also: