Top Description Methods
org.hibernate.boot

public Interface SessionFactoryBuilder

Known Direct Subinterfaces
org.hibernate.boot.spi.SessionFactoryBuilderImplementor
Known Direct Implementers
org.hibernate.boot.spi.AbstractDelegatingSessionFactoryBuilder
Imports
java.util.function.Supplier, org.hibernate.CustomEntityDirtinessStrategy, .EntityNameResolver, .Incubating, .Interceptor, .SessionFactory, .SessionFactoryObserver, org.hibernate.cache.spi.TimestampsCacheFactory, org.hibernate.context.spi.CurrentTenantIdentifierResolver, org.hibernate.jpa.spi.JpaCompliance, org.hibernate.loader.BatchFetchStyle, org.hibernate.proxy.EntityNotFoundDelegate, org.hibernate.query.NullPrecedence, org.hibernate.query.sqm.function.SqmFunctionDescriptor, org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode, .StatementInspector, org.hibernate.type.format.FormatMapper

The contract for building a SessionFactory given a number of options.
Authors
Steve Ebersole, Gail Badner
Since
5.0

Method Summary

Modifier and TypeMethod and Description
public SessionFactoryBuilder

Returns:

this, for method chaining
addEntityNameResolver
(EntityNameResolver...
The entityNameResolvers to add
entityNameResolvers
)

Specifies one or more entity name resolvers.

public SessionFactoryBuilder

Returns:

this, for method chaining
addSessionFactoryObservers
(SessionFactoryObserver...
The observers to add
observers
)

Specifies one or more observers.

public SessionFactoryBuilder
public SessionFactoryBuilder

Returns:

this, for method chaining
applyAutoClosing
(boolean
true indicates they should be auto-closed; false indicates not.
enabled
)

Specifies whether org.hibernate.Sessions should be automatically closed at the end of the transaction.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyAutoFlushing
(boolean
true indicates they should be auto-flushed; false indicates not.
enabled
)

Applies whether org.hibernate.Sessions should be automatically flushed at the end of the transaction.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyAutomaticEvictionOfCollectionCaches
(boolean
true indicates that these collection caches should be evicted automatically.
enabled
)

When using bidirectional many-to-one associations and caching the one-to-many side it is expected that both sides of the association are managed (actually that is true of all bidirectional associations).

public SessionFactoryBuilder

Returns:

this, for method chaining
applyBatchFetchStyle
(BatchFetchStyle
The style to use
style
)

Deprecated since 6.0. : an appropriate style is selected
What style of batching should be used?
public SessionFactoryBuilder

Returns:

this, for method chaining
applyBeanManager
(Object
The CDI BeanManager to use
beanManager
)

Specifies a CDI jakarta.enterprise.inject.spi.BeanManager.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyCacheRegionPrefix
(String
The prefix.
prefix
)

Specify a prefix to prepended to all cache region names.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyCollectionsInDefaultFetchGroup
(boolean
true collections should be included, false they should not. Default is true.
enabled
)

Should collections be included in the default fetch group when bytecode enhancement is used?

public SessionFactoryBuilder

Returns:

this, for method chaining
applyConnectionHandlingMode
(PhysicalConnectionHandlingMode
The handling mode to apply
connectionHandlingMode
)

Specifies the connection handling mode for JDBC connections.

public SessionFactoryBuilder
applyConnectionProviderDisablesAutoCommit(boolean providerDisablesAutoCommit)

public SessionFactoryBuilder

Returns:

this, for method chaining
applyCurrentTenantIdentifierResolver
(CurrentTenantIdentifierResolver<?>
The resolution strategy to use.
resolver
)

Specifies a CurrentTenantIdentifierResolver that is responsible for resolving the current tenant identifier.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyCustomEntityDirtinessStrategy
(CustomEntityDirtinessStrategy
The custom strategy to be used.
strategy
)

Specifies a CustomEntityDirtinessStrategy.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyDefaultBatchFetchSize
(int
The size to use for batch fetching for entities/collections which do not specify an explicit batch fetch size.
size
)

Specifies a default batch fetch size for all entities and collections which do not otherwise specify a batch fetch size.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyDefaultNullPrecedence
(NullPrecedence
The default null precedence to use.
nullPrecedence
)

Apply a null precedence, NULLS FIRST or NULLS LAST, to order by clauses rendered in SQL queries.

public SessionFactoryBuilder
applyDelayedEntityLoaderCreations(boolean delay)

Should entity loaders be generated immediately?

public SessionFactoryBuilder

Returns:

this, for method chaining
applyDirectReferenceCaching
(boolean
true indicates that applicable entities will be stored into the second-level cache directly by reference; false indicates that all entities will be stored via the extraction approach.
enabled
)

Generally, Hibernate will extract the information from an entity and put that extracted information into the second-level cache.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyEntityNotFoundDelegate
(EntityNotFoundDelegate
The delegate/strategy to use.
entityNotFoundDelegate
)

Specifies an EntityNotFoundDelegate.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyGetGeneratedKeysSupport
(boolean
true indicates we should use JDBC getGeneratedKeys support; false indicates we should not.
enabled
)

Should JDBC java.sql.PreparedStatement#getGeneratedKeys() feature be used for retrieval of *insert-generated* ids?

public SessionFactoryBuilder

Returns:

this, for method chaining
applyIdentifierRollbackSupport
(boolean
true indicates identifiers should be unset; false indicates not.
enabled
)

Should the generated identifier be "unset" when an entity is deleted?

public SessionFactoryBuilder

Returns:

this, for method chaining
applyInterceptor
(Interceptor
The interceptor
interceptor
)

Specifies an Interceptor associated with the SessionFactory, which will be used by all sessions unless an interceptor is explicitly specified using org.hibernate.SessionBuilder#interceptor.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyJdbcBatchingForVersionedEntities
(boolean
The batch size to use.
enabled
)

This setting controls whether versioned entities will be included in JDBC batching.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyJdbcBatchSize
(int
The batch size to use.
size
)

Specifies the maximum number of statements to batch together in a JDBC batch for insert, update and delete operations.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyJdbcFetchSize
(int
The fetch size to be passed to the driver.
size
)

Apply a fetch size to the JDBC driver for fetching results.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyJsonFormatMapper
(FormatMapper
The FormatMapper to use.
jsonFormatMapper
)

Specifies a format mapper to use for serialization/deserialization of JSON properties.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyJtaTrackingByThread
(boolean
true indicates we should track by thread; false indicates not
enabled
)

If using the built-in JTA-based org.hibernate.resource.transaction.spi.TransactionCoordinator or org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder, should it track JTA transactions by thread in an attempt to detect timeouts?

public SessionFactoryBuilder

Returns:

this, for method chaining
applyLazyInitializationOutsideTransaction
(boolean
true indicates initialization outside the transaction should be allowed; false indicates it should not.
enabled
)

Should the application be allowed to initialize uninitialized lazy state outside the bounds of a transaction?

public SessionFactoryBuilder

Returns:

this, for method chaining
applyMaximumFetchDepth
(int
The depth for limiting joins.
depth
)

Apply a limit to the depth Hibernate will use for outer joins.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyMinimalPutsForCaching
(boolean
true indicates Hibernate should first check whether data exists and only push to the cache if it does not already exist. false indicates to perform the default behavior.
enabled
)

By default, Hibernate will always just push data into the cache without first checking if that data already exists.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyMultiTenancy
(boolean
True if multi-tenancy in use.
enabled
)

Specifies whether multi-tenancy is enabled

public SessionFactoryBuilder

Returns:

this, for method chaining
applyName
(String
The name to use
sessionFactoryName
)

Specifies a name for the SessionFactory.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyNameAsJndiName
(boolean
true indicates that the name specified in applyName will be used for binding the SessionFactory into JNDI.
isJndiName
)

Specifies that the SessionFactory should be registered in JNDI, under the name specified using applyName(String).

public SessionFactoryBuilder

Returns:

this, for method chaining
applyNamedQueryCheckingOnStartup
(boolean
true indicates that they should; false indicates they should not.
enabled
)

Should named queries be checked on startup?

public SessionFactoryBuilder

Returns:

this, for method chaining
applyNullabilityChecking
(boolean
true indicates that Hibernate should perform nullness checking; false indicates it should not.
enabled
)

Should attributes using columns marked as not-null be checked (by Hibernate) for nullness, or should this be left as a job for the database?

public SessionFactoryBuilder

Returns:

this, for method chaining
applyOrderingOfInserts
(boolean
true indicates that ordering should be enabled; false indicates not
enabled
)

Specify whether ordering of inserts should be enabled.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyOrderingOfUpdates
(boolean
true indicates that ordering should be enabled; false indicates not
enabled
)

Specify whether ordering of updates should be enabled.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyPreferUserTransactions
(boolean
true indicates we should prefer jakarta.transaction.UserTransaction; false indicates we should prefer jakarta.transaction.Transaction
preferUserTransactions
)

If using the built-in JTA-based org.hibernate.resource.transaction.spi.TransactionCoordinator or org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder, should it prefer to use jakarta.transaction.UserTransaction in preference to jakarta.transaction.Transaction?

public SessionFactoryBuilder

Returns:

this, for method chaining
applyQueryCacheSupport
(boolean
true indicates we should enable the use of second level query caching; false indicates we should disable the use of second level query caching.
enabled
)

Should second level query caching support be enabled?

public SessionFactoryBuilder

Returns:

this, for method chaining
applyScrollableResultsSupport
(boolean
true to enable this support, false to disable it
enabled
)

Should scrollable results be supported in queries?

public SessionFactoryBuilder

Returns:

this, for method chaining
applySecondLevelCacheSupport
(boolean
true indicates we should enable the use of second level caching; false indicates we should disable the use of second level caching.
enabled
)

Should second level caching support be enabled?

public SessionFactoryBuilder

Returns:

this, for method chaining
applySqlComments
(boolean
true indicates comments should be applied; false indicates not.
enabled
)

Should Hibernate apply comments to SQL it generates?

public SessionFactoryBuilder

Returns:

this, for method chaining
applySqlFunction
(String
The function name to register it under
registrationName
,
SqmFunctionDescriptor functionDescriptor)

Register a SQL function with the underlying org.hibernate.query.sqm.function.SqmFunctionRegistry.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyStatelessInterceptor
(Class<? extends Interceptor>
The interceptor class
statelessInterceptorClass
)

Specifies an interceptor Class associated with the SessionFactory, which is used to instantiate a new interceptor for each session, unless an interceptor is explicitly specified using org.hibernate.SessionBuilder#interceptor.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyStatelessInterceptor
(Supplier<? extends Interceptor>
Supplier instance which is used to retrieve the interceptor
statelessInterceptorSupplier
)

Specifies an interceptor Supplier associated with the SessionFactory, which is used to obtain an interceptor for each session, unless an interceptor is explicitly specified using org.hibernate.SessionBuilder#interceptor.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyStatementInspector
(StatementInspector
The StatementInspector
statementInspector
)

Specifies a StatementInspector associated with the SessionFactory, which will be used by all sessions unless a statement inspector is explicitly specified using org.hibernate.SessionBuilder#statementInspector

public SessionFactoryBuilder

Returns:

this, for method chaining
applyStatisticsSupport
(boolean
true indicates that statistics gathering should be enabled; false indicates not.
enabled
)

Specifies whether statistics gathering is enabled.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyStructuredCacheEntries
(boolean
true indicates that structured (human-readable) cache entries should be used; false indicates that the native entry structure should be used.
enabled
)

By default, Hibernate stores data in the cache in its own optimized format.

public SessionFactoryBuilder

Returns:

this, for method chaining
applySubselectFetchEnabled
(boolean
true indicates that subselect fetching is enabled
enabled
)

Enable the use of subselect fetching.

public SessionFactoryBuilder
public SessionFactoryBuilder
public SessionFactoryBuilder

Returns:

this, for method chaining
applyValidatorFactory
(Object
The Bean Validation ValidatorFactory to use
validatorFactory
)

Specifies a Bean Validation jakarta.validation.ValidatorFactory.

public SessionFactoryBuilder

Returns:

this, for method chaining
applyXmlFormatMapper
(FormatMapper
The FormatMapper to use.
xmlFormatMapper
)

Specifies a format mapper to use for serialization/deserialization of XML properties.

public SessionFactory

Returns:

The built SessionFactory.
build
()

After all options have been set, build the SessionFactory.

public SessionFactoryBuilder
enableJpaClosedCompliance(boolean enabled)

public SessionFactoryBuilder
public SessionFactoryBuilder
public SessionFactoryBuilder
enableJpaQueryCompliance(boolean enabled)

public SessionFactoryBuilder
public SessionFactoryBuilder
enableReleaseResourcesOnCloseEnabled(boolean enable)

Should resources held by an jakarta.persistence.EntityManager be released immediately on close?