Top Description Methods
org.hibernate

public Interface SessionBuilder

Known Direct Subinterfaces
org.hibernate.SharedSessionBuilder, org.hibernate.engine.spi.SessionBuilderImplementor
Known Direct Implementers
org.hibernate.engine.spi.AbstractDelegatingSessionBuilder
Imports
java.sql.Connection, java.util.TimeZone, org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode, .StatementInspector

Allows creation of a new Session with specific options.
Author
Steve Ebersole

Method Summary

Modifier and TypeMethod and Description
public SessionBuilder

Returns:

this, for method chaining
autoClear
(boolean
Whether the Session should be automatically cleared
autoClear
)

Should the session be automatically cleared on a failed transaction?

public SessionBuilder

Returns:

this, for method chaining
autoClose
(boolean
Should the session be automatically closed
autoClose
)

Should the session be automatically closed after transaction completion?

public SessionBuilder

Returns:

this, for method chaining
autoJoinTransactions
(boolean
Should JTA transactions be automatically joined
autoJoinTransactions
)

Should the session built automatically join in any ongoing JTA transactions.

public SessionBuilder

Returns:

this, for method chaining
clearEventListeners
()

Remove all listeners intended for the built session currently held here, including any auto-apply ones; in other words, start with a clean slate.

public SessionBuilder

Returns:

this, for method chaining
connection
(Connection
The connection to use.
connection
)

Adds a specific connection to the session options.

public SessionBuilder

Returns:

this, for method chaining
connectionHandlingMode
(PhysicalConnectionHandlingMode
The connection handling mode to use.
mode
)

Signifies that the connection release mode from the original session should be used to create the new session.

public SessionBuilder

Returns:

this, for method chaining
eventListeners
(SessionEventListener...
The listeners to incorporate into the built Session
listeners
)

Add one or more SessionEventListener instances to the list of listeners for the new session to be built.

public SessionBuilder

Returns:

this, for method chaining
flushMode
(FlushMode
The initial FlushMode to use for the opened Session
flushMode
)

Specify the initial FlushMode to use for the opened Session

public SessionBuilder

Returns:

this, for method chaining
interceptor
(Interceptor
The interceptor to use.
interceptor
)

Adds a specific interceptor to the session options.

public SessionBuilder
public SessionBuilder

Returns:

this, for method chaining
noInterceptor
()

Signifies that no Interceptor should be used.

public Session

Returns:

The session
openSession
()

Opens a session with the specified options.

public SessionBuilder

Returns:

this, for method chaining
statementInspector
(StatementInspector
The StatementInspector to use.
statementInspector
)

Applies the given StatementInspector to the session.

public SessionBuilder

Returns:

this, for method chaining
tenantIdentifier
(String
The tenant identifier.
tenantIdentifier
)

Deprecated for removal. Use tenantIdentifier(Object) instead
Define the tenant identifier to be associated with the opened session.
public SessionBuilder

Returns:

this, for method chaining
tenantIdentifier
(Object
The tenant identifier.
tenantIdentifier
)

Define the tenant identifier to be associated with the opened session.

Method Detail

autoClearback to summary
public SessionBuilder autoClear(boolean autoClear)

Should the session be automatically cleared on a failed transaction?

Parameters
autoClear:boolean

Whether the Session should be automatically cleared

Returns:SessionBuilder

this, for method chaining

autoCloseback to summary
public SessionBuilder autoClose(boolean autoClose)

Should the session be automatically closed after transaction completion?

Parameters
autoClose:boolean

Should the session be automatically closed

Returns:SessionBuilder

this, for method chaining

See Also
jakarta.persistence.PersistenceContextType
autoJoinTransactionsback to summary
public SessionBuilder autoJoinTransactions(boolean autoJoinTransactions)

Should the session built automatically join in any ongoing JTA transactions.

Parameters
autoJoinTransactions:boolean

Should JTA transactions be automatically joined

Returns:SessionBuilder

this, for method chaining

See Also
jakarta.persistence.SynchronizationType#SYNCHRONIZED
clearEventListenersback to summary
public SessionBuilder clearEventListeners()

Remove all listeners intended for the built session currently held here, including any auto-apply ones; in other words, start with a clean slate.

Returns:SessionBuilder

this, for method chaining

connectionback to summary
public SessionBuilder connection(Connection connection)

Adds a specific connection to the session options.

Parameters
connection:Connection

The connection to use.

Returns:SessionBuilder

this, for method chaining

connectionHandlingModeback to summary
public SessionBuilder connectionHandlingMode(PhysicalConnectionHandlingMode mode)

Signifies that the connection release mode from the original session should be used to create the new session.

Parameters
mode:PhysicalConnectionHandlingMode

The connection handling mode to use.

Returns:SessionBuilder

this, for method chaining

eventListenersback to summary
public SessionBuilder eventListeners(SessionEventListener... listeners)

Add one or more SessionEventListener instances to the list of listeners for the new session to be built.

Parameters
listeners:SessionEventListener[]

The listeners to incorporate into the built Session

Returns:SessionBuilder

this, for method chaining

flushModeback to summary
public SessionBuilder flushMode(FlushMode flushMode)

Specify the initial FlushMode to use for the opened Session

Parameters
flushMode:FlushMode

The initial FlushMode to use for the opened Session

Returns:SessionBuilder

this, for method chaining

See Also
jakarta.persistence.PersistenceContextType
interceptorback to summary
public SessionBuilder interceptor(Interceptor interceptor)

Adds a specific interceptor to the session options.

Parameters
interceptor:Interceptor

The interceptor to use.

Returns:SessionBuilder

this, for method chaining

jdbcTimeZoneback to summary
public SessionBuilder jdbcTimeZone(TimeZone timeZone)
noInterceptorback to summary
public SessionBuilder noInterceptor()

Signifies that no Interceptor should be used.

By default, if no Interceptor is explicitly specified, the Interceptor associated with the SessionFactory is inherited by the new Session.

Calling interceptor(Interceptor) with null has the same effect.

Returns:SessionBuilder

this, for method chaining

openSessionback to summary
public Session openSession()

Opens a session with the specified options.

Returns:Session

The session

statementInspectorback to summary
public SessionBuilder statementInspector(StatementInspector statementInspector)

Applies the given StatementInspector to the session.

Parameters
statementInspector:StatementInspector

The StatementInspector to use.

Returns:SessionBuilder

this, for method chaining

tenantIdentifierback to summary
public SessionBuilder tenantIdentifier(String tenantIdentifier)

Deprecated

for removal.

Use tenantIdentifier(Object) instead

Define the tenant identifier to be associated with the opened session.

Parameters
tenantIdentifier:String

The tenant identifier.

Returns:SessionBuilder

this, for method chaining

Annotations
@Deprecated
forRemoval:true
tenantIdentifierback to summary
public SessionBuilder tenantIdentifier(Object tenantIdentifier)

Define the tenant identifier to be associated with the opened session.

Parameters
tenantIdentifier:Object

The tenant identifier.

Returns:SessionBuilder

this, for method chaining

Since
6.4