Package org.hibernate

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.

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.

 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: