Interface SessionFactoryBuilder
- All Known Subinterfaces:
SessionFactoryBuilderImplementor
- All Known Implementing Classes:
AbstractDelegatingSessionFactoryBuilder
,AbstractDelegatingSessionFactoryBuilderImplementor
,SessionFactoryBuilderImpl
SessionFactory
given a specified set of options.- Since:
- 5.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionaddEntityNameResolver
(EntityNameResolver... entityNameResolvers) Specifies one or more entity name resolvers.addSessionFactoryObservers
(SessionFactoryObserver... observers) Specifies one or more observers.allowOutOfTransactionUpdateOperations
(boolean allow) applyAutoClosing
(boolean enabled) Specifies whetherSession
s should be automatically closed at the end of the transaction.applyAutoFlushing
(boolean enabled) Applies whetherSession
s should be automatically flushed at the end of the transaction.applyAutomaticEvictionOfCollectionCaches
(boolean 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).Deprecated.: an appropriate style is selectedapplyBeanManager
(Object beanManager) Specifies a CDIBeanManager
.applyCacheRegionPrefix
(String prefix) Specify a prefix to prepended to all cache region names.applyCollectionsInDefaultFetchGroup
(boolean enabled) Should collections be included in the default fetch group when bytecode enhancement is used?applyConnectionHandlingMode
(PhysicalConnectionHandlingMode connectionHandlingMode) Specifies the connection handling mode for JDBC connections.applyConnectionProviderDisablesAutoCommit
(boolean providerDisablesAutoCommit) Specifies aCurrentTenantIdentifierResolver
that is responsible for resolving the current tenant identifier.Specifies aCustomEntityDirtinessStrategy
.applyDefaultBatchFetchSize
(int size) Specifies a default batch fetch size for all entities and collections which do not otherwise specify a batch fetch size.applyDefaultNullPrecedence
(NullPrecedence nullPrecedence) Apply a null precedence,NULLS FIRST
orNULLS LAST
, toorder by
clauses rendered in SQL queries.applyDelayedEntityLoaderCreations
(boolean delay) Should entity loaders be generated immediately? Or should the creation be delayed until first need?applyDirectReferenceCaching
(boolean enabled) Generally, Hibernate will extract the information from an entity and put that extracted information into the second-level cache.applyEntityNotFoundDelegate
(EntityNotFoundDelegate entityNotFoundDelegate) Specifies anEntityNotFoundDelegate
.applyGetGeneratedKeysSupport
(boolean enabled) Should JDBCStatement.getGeneratedKeys()
feature be used for retrieval of *insert-generated* ids?applyIdentifierRollbackSupport
(boolean enabled) Should the generated identifier be "unset" when an entity is deleted?applyInterceptor
(Interceptor interceptor) Specifies anInterceptor
associated with theSessionFactory
, which will be used by all sessions unless an interceptor is explicitly specified usingSessionBuilder.interceptor(org.hibernate.Interceptor)
.applyJdbcBatchingForVersionedEntities
(boolean enabled) This setting controls whether versioned entities will be included in JDBC batching.applyJdbcBatchSize
(int size) Specifies the maximum number of statements to batch together in a JDBC batch for insert, update and delete operations.applyJdbcFetchSize
(int size) Apply a fetch size to the JDBC driver for fetching results.applyJsonFormatMapper
(FormatMapper jsonFormatMapper) Specifies aformat mapper
to use for serialization/deserialization of JSON properties.applyJtaTrackingByThread
(boolean enabled) If using the built-in JTA-basedTransactionCoordinator
orTransactionCoordinatorBuilder
, should it track JTA transactions by thread in an attempt to detect timeouts?applyLazyInitializationOutsideTransaction
(boolean enabled) Should the application be allowed to initialize uninitialized lazy state outside the bounds of a transaction?applyMaximumFetchDepth
(int depth) Apply a limit to the depth Hibernate will use for outer joins.applyMinimalPutsForCaching
(boolean enabled) By default, Hibernate will always just push data into the cache without first checking if that data already exists.applyMultiTenancy
(boolean enabled) Specifies whether multitenancy is enabled via use of aMultiTenantConnectionProvider
.Specifies a name for theSessionFactory
.applyNameAsJndiName
(boolean isJndiName) Specifies that theSessionFactory
should be registered in JNDI, under the name specified usingapplyName(String)
.applyNamedQueryCheckingOnStartup
(boolean enabled) Should named queries be checked on startup?applyNullabilityChecking
(boolean 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?applyOrderingOfInserts
(boolean enabled) Specify whether ordering of inserts should be enabled.applyOrderingOfUpdates
(boolean enabled) Specify whether ordering of updates should be enabled.applyPreferUserTransactions
(boolean preferUserTransactions) If using the built-in JTA-basedTransactionCoordinator
orTransactionCoordinatorBuilder
, should it prefer to useUserTransaction
in preference toTransaction
?applyQueryCacheLayout
(CacheLayout cacheLayout) Specifies the defaultCacheLayout
to use for query cache entries.applyQueryCacheSupport
(boolean enabled) Should second level query caching support be enabled?applyScrollableResultsSupport
(boolean enabled) Should scrollable results be supported in queries? We ask the JDBC driver whether it supports scrollable result sets as the default for this setting, but some drivers do not accurately report this via DatabaseMetaData.applySecondLevelCacheSupport
(boolean enabled) Should second level caching support be enabled?applySqlComments
(boolean enabled) Should Hibernate apply comments to SQL it generates?applySqlFunction
(String registrationName, SqmFunctionDescriptor functionDescriptor) Register aSQL function
with the underlyingSqmFunctionRegistry
.applyStatelessInterceptor
(Class<? extends Interceptor> statelessInterceptorClass) Specifies an interceptorClass
associated with theSessionFactory
, which is used to instantiate a new interceptor for each session, unless an interceptor is explicitly specified usingSessionBuilder.interceptor(org.hibernate.Interceptor)
.applyStatelessInterceptor
(Supplier<? extends Interceptor> statelessInterceptorSupplier) Specifies an interceptorSupplier
associated with theSessionFactory
, which is used to obtain an interceptor for each session, unless an interceptor is explicitly specified usingSessionBuilder.interceptor(org.hibernate.Interceptor)
.applyStatementInspector
(StatementInspector statementInspector) Specifies aStatementInspector
associated with theSessionFactory
, which will be used by all sessions unless a statement inspector is explicitly specified usingSessionBuilder.statementInspector(org.hibernate.resource.jdbc.spi.StatementInspector)
applyStatisticsSupport
(boolean enabled) Specifies whether statistics gathering is enabled.applyStructuredCacheEntries
(boolean enabled) By default, Hibernate stores data in the cache in its own optimized format.applySubselectFetchEnabled
(boolean enabled) Enable the use of subselect fetching.Specifies how temporary tables should be created or dropped with respect to transaction handling.Specifies aTimestampsCacheFactory
.applyValidatorFactory
(Object validatorFactory) Specifies a Bean ValidationValidatorFactory
.applyXmlFormatMapper
(FormatMapper xmlFormatMapper) Specifies aformat mapper
to use for serialization/deserialization of XML properties.build()
After all options have been set, build the SessionFactory.enableJpaCascadeCompliance
(boolean enabled) enableJpaClosedCompliance
(boolean enabled) enableJpaListCompliance
(boolean enabled) Deprecated.UseMappingSettings.DEFAULT_LIST_SEMANTICS
insteadenableJpaOrderByMappingCompliance
(boolean enabled) enableJpaQueryCompliance
(boolean enabled) enableJpaTransactionCompliance
(boolean enabled) enableReleaseResourcesOnCloseEnabled
(boolean enable) Should resources held by anEntityManager
be released immediately on close?
-
Method Details
-
applyValidatorFactory
Specifies a Bean ValidationValidatorFactory
.- Parameters:
validatorFactory
- The Bean ValidationValidatorFactory
to use- Returns:
this
, for method chaining- See Also:
- API Note:
- De-typed to avoid a hard dependency on the Bean Validation jar
-
applyBeanManager
Specifies a CDIBeanManager
.- Parameters:
beanManager
- The CDIBeanManager
to use- Returns:
this
, for method chaining- See Also:
- API Note:
- De-typed to avoid a hard dependency on the CDI jar
-
applyName
Specifies a name for theSessionFactory
.- Parameters:
sessionFactoryName
- The name to use- Returns:
this
, for method chaining- See Also:
-
applyNameAsJndiName
Specifies that theSessionFactory
should be registered in JNDI, under the name specified usingapplyName(String)
.- Parameters:
isJndiName
-true
indicates that the name specified inapplyName(java.lang.String)
will be used for binding the SessionFactory into JNDI.- Returns:
this
, for method chaining- See Also:
-
applyAutoClosing
Specifies whetherSession
s should be automatically closed at the end of the transaction.- Parameters:
enabled
-true
indicates they should be auto-closed;false
indicates not.- Returns:
this
, for method chaining- See Also:
-
applyAutoFlushing
Applies whetherSession
s should be automatically flushed at the end of the transaction.- Parameters:
enabled
-true
indicates they should be auto-flushed;false
indicates not.- Returns:
this
, for method chaining- See Also:
-
applyStatisticsSupport
Specifies whether statistics gathering is enabled.- Parameters:
enabled
-true
indicates that statistics gathering should be enabled;false
indicates not.- Returns:
this
, for method chaining- See Also:
-
applyInterceptor
Specifies anInterceptor
associated with theSessionFactory
, which will be used by all sessions unless an interceptor is explicitly specified usingSessionBuilder.interceptor(org.hibernate.Interceptor)
.- Parameters:
interceptor
- The interceptor- Returns:
this
, for method chaining- See Also:
-
applyStatelessInterceptor
SessionFactoryBuilder applyStatelessInterceptor(Class<? extends Interceptor> statelessInterceptorClass) Specifies an interceptorClass
associated with theSessionFactory
, which is used to instantiate a new interceptor for each session, unless an interceptor is explicitly specified usingSessionBuilder.interceptor(org.hibernate.Interceptor)
.- Parameters:
statelessInterceptorClass
- The interceptor class- Returns:
this
, for method chaining- See Also:
-
applyStatelessInterceptor
SessionFactoryBuilder applyStatelessInterceptor(Supplier<? extends Interceptor> statelessInterceptorSupplier) Specifies an interceptorSupplier
associated with theSessionFactory
, which is used to obtain an interceptor for each session, unless an interceptor is explicitly specified usingSessionBuilder.interceptor(org.hibernate.Interceptor)
.- Parameters:
statelessInterceptorSupplier
-Supplier
instance which is used to retrieve the interceptor- Returns:
this
, for method chaining- See Also:
-
applyStatementInspector
Specifies aStatementInspector
associated with theSessionFactory
, which will be used by all sessions unless a statement inspector is explicitly specified usingSessionBuilder.statementInspector(org.hibernate.resource.jdbc.spi.StatementInspector)
- Parameters:
statementInspector
- The StatementInspector- Returns:
this
, for method chaining- See Also:
-
addSessionFactoryObservers
Specifies one or more observers. May be called multiple times to add additional observers.- Parameters:
observers
- The observers to add- Returns:
this
, for method chaining- See Also:
-
applyCustomEntityDirtinessStrategy
Specifies aCustomEntityDirtinessStrategy
.- Parameters:
strategy
- The custom strategy to be used.- Returns:
this
, for method chaining- See Also:
-
addEntityNameResolver
Specifies one or more entity name resolvers. May be called multiple times to add additional resolvers.- Parameters:
entityNameResolvers
- The entityNameResolvers to add- Returns:
this
, for method chaining
-
applyEntityNotFoundDelegate
Specifies anEntityNotFoundDelegate
. AnEntityNotFoundDelegate
is a strategy that accounts for different exceptions thrown between Hibernate and JPA when an entity cannot be found.- Parameters:
entityNotFoundDelegate
- The delegate/strategy to use.- Returns:
this
, for method chaining
-
applyIdentifierRollbackSupport
Should the generated identifier be "unset" when an entity is deleted?- Parameters:
enabled
-true
indicates identifiers should be unset;false
indicates not.- Returns:
this
, for method chaining- See Also:
-
applyNullabilityChecking
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?- Parameters:
enabled
-true
indicates that Hibernate should perform nullness checking;false
indicates it should not.- Returns:
this
, for method chaining- See Also:
-
applyLazyInitializationOutsideTransaction
Should the application be allowed to initialize uninitialized lazy state outside the bounds of a transaction?- Parameters:
enabled
-true
indicates initialization outside the transaction should be allowed;false
indicates it should not.- Returns:
this
, for method chaining- See Also:
-
applyTempTableDdlTransactionHandling
SessionFactoryBuilder applyTempTableDdlTransactionHandling(TempTableDdlTransactionHandling handling) Specifies how temporary tables should be created or dropped with respect to transaction handling.- See Also:
-
applyBatchFetchStyle
Deprecated.: an appropriate style is selectedWhat style of batching should be used?- Parameters:
style
- The style to use- Returns:
this
, for method chaining- See Also:
-
applyDelayedEntityLoaderCreations
Should entity loaders be generated immediately? Or should the creation be delayed until first need? -
applyDefaultBatchFetchSize
Specifies a default batch fetch size for all entities and collections which do not otherwise specify a batch fetch size.- Parameters:
size
- The size to use for batch fetching for entities/collections which do not specify an explicit batch fetch size.- Returns:
this
, for method chaining- See Also:
-
applyMaximumFetchDepth
Apply a limit to the depth Hibernate will use for outer joins.Note that this is different to an overall limit on the number of joins.
- Parameters:
depth
- The depth for limiting joins.- Returns:
this
, for method chaining- See Also:
-
applySubselectFetchEnabled
Enable the use of subselect fetching.- Parameters:
enabled
-true
indicates that subselect fetching is enabled- Returns:
this
, for method chaining- See Also:
-
applyDefaultNullPrecedence
Apply a null precedence,NULLS FIRST
orNULLS LAST
, toorder by
clauses rendered in SQL queries.- Parameters:
nullPrecedence
- The default null precedence to use.- Returns:
this
, for method chaining- See Also:
-
applyOrderingOfInserts
Specify whether ordering of inserts should be enabled.This allows more efficient SQL execution via the use of batching for the inserts; the cost is that the determination of the ordering is far less efficient than not ordering.
- Parameters:
enabled
-true
indicates that ordering should be enabled;false
indicates not- Returns:
this
, for method chaining- See Also:
-
applyOrderingOfUpdates
Specify whether ordering of updates should be enabled.This allows more efficient SQL execution via the use of batching for the updates; the cost is that the determination of the ordering is far less efficient than not ordering.
- Parameters:
enabled
-true
indicates that ordering should be enabled;false
indicates not- Returns:
this
, for method chaining- See Also:
-
applyMultiTenancy
Specifies whether multitenancy is enabled via use of aMultiTenantConnectionProvider
.Note that this setting does not affect discriminator-based multitenancy.
- Parameters:
enabled
- True if multi-tenancy in use via aMultiTenantConnectionProvider
.- Returns:
this
, for method chaining- See Also:
-
applyCurrentTenantIdentifierResolver
SessionFactoryBuilder applyCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver<?> resolver) Specifies aCurrentTenantIdentifierResolver
that is responsible for resolving the current tenant identifier.- Parameters:
resolver
- The resolution strategy to use.- Returns:
this
, for method chaining- See Also:
-
applyJtaTrackingByThread
If using the built-in JTA-basedTransactionCoordinator
orTransactionCoordinatorBuilder
, should it track JTA transactions by thread in an attempt to detect timeouts?- Parameters:
enabled
-true
indicates we should track by thread;false
indicates not- Returns:
this
, for method chaining- See Also:
-
applyPreferUserTransactions
If using the built-in JTA-basedTransactionCoordinator
orTransactionCoordinatorBuilder
, should it prefer to useUserTransaction
in preference toTransaction
?- Parameters:
preferUserTransactions
-true
indicates we should preferUserTransaction
;false
indicates we should preferTransaction
- Returns:
this
, for method chaining- See Also:
-
applyNamedQueryCheckingOnStartup
Should named queries be checked on startup?- Parameters:
enabled
-true
indicates that they should;false
indicates they should not.- Returns:
this
, for method chaining- See Also:
-
applySecondLevelCacheSupport
Should second level caching support be enabled?- Parameters:
enabled
-true
indicates we should enable the use of second level caching;false
indicates we should disable the use of second level caching.- Returns:
this
, for method chaining- See Also:
-
applyQueryCacheSupport
Should second level query caching support be enabled?- Parameters:
enabled
-true
indicates we should enable the use of second level query caching;false
indicates we should disable the use of second level query caching.- Returns:
this
, for method chaining- See Also:
-
applyQueryCacheLayout
Specifies the defaultCacheLayout
to use for query cache entries.- Parameters:
cacheLayout
- The cache layout to use.- Returns:
this
, for method chaining- Since:
- 6.5
- See Also:
-
applyTimestampsCacheFactory
Specifies aTimestampsCacheFactory
.- Parameters:
factory
- TheTimestampsCacheFactory
to use- Returns:
this
, for method chaining- See Also:
-
applyCacheRegionPrefix
Specify a prefix to prepended to all cache region names.- Parameters:
prefix
- The prefix.- Returns:
this
, for method chaining- See Also:
-
applyMinimalPutsForCaching
By default, Hibernate will always just push data into the cache without first checking if that data already exists. For some caches (mainly distributed caches) this can have a major adverse performance impact. For these caches, it is best to enable this "minimal puts" feature.Cache integrations also report whether "minimal puts" should be enabled by default. So it's very rare that users need to set this, generally speaking.
- Parameters:
enabled
-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.- Returns:
this
, for method chaining- See Also:
-
applyStructuredCacheEntries
By default, Hibernate stores data in the cache in its own optimized format. However, that format is impossible to "read" if browsing the cache. The use of "structured" cache entries allows the cached data to be read.- Parameters:
enabled
-true
indicates that structured (human-readable) cache entries should be used;false
indicates that the native entry structure should be used.- Returns:
this
, for method chaining- See Also:
-
applyDirectReferenceCaching
Generally, Hibernate will extract the information from an entity and put that extracted information into the second-level cache. This is by far the safest way to second-level cache persistent data. However, there are some cases where it is safe to cache the entity instance directly. This setting controls whether that is used in those cases.- Parameters:
enabled
-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.- Returns:
this
, for method chaining- See Also:
-
applyAutomaticEvictionOfCollectionCaches
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). However, in this case, if the user forgets to manage the one-to-many side stale data can be left in the second-level cache.Warning: enabling this will have a performance impact. Hence why it is disabled by default (for good citizens) and is an opt-in setting.
- Parameters:
enabled
-true
indicates that these collection caches should be evicted automatically.- Returns:
this
, for method chaining- See Also:
-
applyJdbcBatchSize
Specifies the maximum number of statements to batch together in a JDBC batch for insert, update and delete operations. A non-zero number enables batching, but really only a number greater than zero will have any effect. If used, a number great than 5 is suggested.- Parameters:
size
- The batch size to use.- Returns:
this
, for method chaining- See Also:
-
applyJdbcBatchingForVersionedEntities
This setting controls whether versioned entities will be included in JDBC batching. The reason being that some JDBC drivers have a problems returning "accurate" update counts from batch statements. This is setting isfalse
by default.- Parameters:
enabled
- The batch size to use.- Returns:
this
, for method chaining- See Also:
-
applyScrollableResultsSupport
Should scrollable results be supported in queries? We ask the JDBC driver whether it supports scrollable result sets as the default for this setting, but some drivers do not accurately report this via DatabaseMetaData. Also, needed if user is supplying connections (and so no Connection is available when we bootstrap).- Parameters:
enabled
-true
to enable this support,false
to disable it- Returns:
this
, for method chaining- See Also:
-
applyGetGeneratedKeysSupport
Should JDBCStatement.getGeneratedKeys()
feature be used for retrieval of *insert-generated* ids?- Parameters:
enabled
-true
indicates we should use JDBC getGeneratedKeys support;false
indicates we should not.- Returns:
this
, for method chaining- See Also:
-
applyJdbcFetchSize
Apply a fetch size to the JDBC driver for fetching results.- Parameters:
size
- The fetch size to be passed to the driver.- Returns:
this
, for method chaining- See Also:
-
applyConnectionHandlingMode
SessionFactoryBuilder applyConnectionHandlingMode(PhysicalConnectionHandlingMode connectionHandlingMode) Specifies the connection handling mode for JDBC connections.- Parameters:
connectionHandlingMode
- The handling mode to apply- Returns:
this
, for method chaining- See Also:
-
applyConnectionProviderDisablesAutoCommit
-
applySqlComments
Should Hibernate apply comments to SQL it generates?- Parameters:
enabled
-true
indicates comments should be applied;false
indicates not.- Returns:
this
, for method chaining- See Also:
-
applySqlFunction
SessionFactoryBuilder applySqlFunction(String registrationName, SqmFunctionDescriptor functionDescriptor) Register aSQL function
with the underlyingSqmFunctionRegistry
.- Parameters:
registrationName
- The function name to register it underfunctionDescriptor
- TheSqmFunctionDescriptor
- Returns:
this
, for method chaining
-
applyCollectionsInDefaultFetchGroup
Should collections be included in the default fetch group when bytecode enhancement is used?- Parameters:
enabled
-true
collections should be included,false
they should not. Default istrue
.- Returns:
this
, for method chaining
-
allowOutOfTransactionUpdateOperations
-
enableReleaseResourcesOnCloseEnabled
Should resources held by anEntityManager
be released immediately on close?The other option is to release them as part of an after transaction callback.
-
enableJpaQueryCompliance
-
enableJpaOrderByMappingCompliance
-
enableJpaTransactionCompliance
-
enableJpaListCompliance
Deprecated.UseMappingSettings.DEFAULT_LIST_SEMANTICS
instead -
enableJpaCascadeCompliance
-
enableJpaClosedCompliance
-
applyJsonFormatMapper
Specifies aformat mapper
to use for serialization/deserialization of JSON properties.- Parameters:
jsonFormatMapper
- TheFormatMapper
to use.- Returns:
this
, for method chaining- See Also:
-
applyXmlFormatMapper
Specifies aformat mapper
to use for serialization/deserialization of XML properties.- Parameters:
xmlFormatMapper
- TheFormatMapper
to use.- Returns:
this
, for method chaining- See Also:
-
build
SessionFactory build()After all options have been set, build the SessionFactory.- Returns:
- The built SessionFactory.
-