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 whetherSessions should be automatically closed at the end of the transaction.applyAutoFlushing(boolean enabled) Applies whetherSessions 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).applyBeanManager(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 aCurrentTenantIdentifierResolverthat 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(Nulls nullPrecedence) Apply a null precedence,NULLS FIRSTorNULLS LAST, toorder byclauses 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 anInterceptorassociated with theSessionFactory, which will be used by all sessions unless an interceptor is explicitly specified usingSessionBuilder.interceptor(org.hibernate.Interceptor).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 mapperto use for serialization/deserialization of JSON properties.applyJtaTrackingByThread(boolean enabled) If using the built-in JTA-basedTransactionCoordinatororTransactionCoordinatorBuilder, 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 theSessionFactoryshould 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-basedTransactionCoordinatororTransactionCoordinatorBuilder, should it prefer to useUserTransactionin preference toTransaction?applyQueryCacheLayout(CacheLayout cacheLayout) Specifies the defaultCacheLayoutto 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 functionwith the underlyingSqmFunctionRegistry.applyStatelessInterceptor(Class<? extends Interceptor> statelessInterceptorClass) Specifies an interceptorClassassociated 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 interceptorSupplierassociated 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 aStatementInspectorassociated with theSessionFactory, which will be used by all sessions unless a statement inspector is explicitly specified usingSessionBuilder.statementInspector(java.util.function.UnaryOperator<java.lang.String>)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.Deprecated, for removal: This API element is subject to removal in a future version.This has no effect and will be removed.applyTenantSchemaMapper(TenantSchemaMapper<?> mapper) Specifies aTenantSchemaMapperthat is responsible for mapping the current tenant identifier to the name of a database schema.Specifies aTimestampsCacheFactory.applyValidatorFactory(Object validatorFactory) Specifies a Bean ValidationValidatorFactory.applyXmlFormatMapper(FormatMapper xmlFormatMapper) Specifies aformat mapperto use for serialization/deserialization of XML properties.build()After all options have been set, build the SessionFactory.enableJpaCascadeCompliance(boolean enabled) Deprecated, for removal: This API element is subject to removal in a future version.No longer has any effect.enableJpaClosedCompliance(boolean enabled) enableJpaOrderByMappingCompliance(boolean enabled) enableJpaQueryCompliance(boolean enabled) enableJpaTransactionCompliance(boolean enabled) enableReleaseResourcesOnCloseEnabled(boolean enable) Deprecated, for removal: This API element is subject to removal in a future version.since "hibernate.discard_pc_on_close" is deprecated
-
Method Details
-
applyValidatorFactory
Specifies a Bean ValidationValidatorFactory.- Parameters:
validatorFactory- The Bean ValidationValidatorFactoryto 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 CDIBeanManagerto 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 theSessionFactoryshould be registered in JNDI, under the name specified usingapplyName(String).- Parameters:
isJndiName-trueindicates 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 whetherSessions should be automatically closed at the end of the transaction.- Parameters:
enabled-trueindicates they should be auto-closed;falseindicates not.- Returns:
this, for method chaining- See Also:
-
applyAutoFlushing
Applies whetherSessions should be automatically flushed at the end of the transaction.- Parameters:
enabled-trueindicates they should be auto-flushed;falseindicates not.- Returns:
this, for method chaining- See Also:
-
applyStatisticsSupport
Specifies whether statistics gathering is enabled.- Parameters:
enabled-trueindicates that statistics gathering should be enabled;falseindicates not.- Returns:
this, for method chaining- See Also:
-
applyInterceptor
Specifies anInterceptorassociated 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 interceptorClassassociated 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 interceptorSupplierassociated 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-Supplierinstance which is used to retrieve the interceptor- Returns:
this, for method chaining- See Also:
-
applyStatementInspector
Specifies aStatementInspectorassociated with theSessionFactory, which will be used by all sessions unless a statement inspector is explicitly specified usingSessionBuilder.statementInspector(java.util.function.UnaryOperator<java.lang.String>)- 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. AnEntityNotFoundDelegateis 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-trueindicates identifiers should be unset;falseindicates 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-trueindicates that Hibernate should perform nullness checking;falseindicates 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-trueindicates initialization outside the transaction should be allowed;falseindicates it should not.- Returns:
this, for method chaining- See Also:
-
applyTempTableDdlTransactionHandling
@Deprecated(since="7.0", forRemoval=true) SessionFactoryBuilder applyTempTableDdlTransactionHandling(TempTableDdlTransactionHandling handling) Deprecated, for removal: This API element is subject to removal in a future version.This has no effect and will be removed.Specifies how temporary tables should be created or dropped with respect to transaction handling.- See Also:
-
applyDelayedEntityLoaderCreations
Should entity loaders be generated immediately? Or should the creation be delayed until first need?- See Also:
-
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-trueindicates that subselect fetching is enabled- Returns:
this, for method chaining- See Also:
-
applyDefaultNullPrecedence
Apply a null precedence,NULLS FIRSTorNULLS LAST, toorder byclauses 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-trueindicates that ordering should be enabled;falseindicates 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-trueindicates that ordering should be enabled;falseindicates 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 aCurrentTenantIdentifierResolverthat is responsible for resolving the current tenant identifier.- Parameters:
resolver- The resolution strategy to use.- Returns:
this, for method chaining- See Also:
-
applyTenantSchemaMapper
Specifies aTenantSchemaMapperthat is responsible for mapping the current tenant identifier to the name of a database schema.- Parameters:
mapper- The mapping strategy to use.- Returns:
this, for method chaining- Since:
- 7.1
- See Also:
-
applyJtaTrackingByThread
If using the built-in JTA-basedTransactionCoordinatororTransactionCoordinatorBuilder, should it track JTA transactions by thread in an attempt to detect timeouts?- Parameters:
enabled-trueindicates we should track by thread;falseindicates not- Returns:
this, for method chaining- See Also:
-
applyPreferUserTransactions
If using the built-in JTA-basedTransactionCoordinatororTransactionCoordinatorBuilder, should it prefer to useUserTransactionin preference toTransaction?- Parameters:
preferUserTransactions-trueindicates we should preferUserTransaction;falseindicates we should preferTransaction- Returns:
this, for method chaining- See Also:
-
applyNamedQueryCheckingOnStartup
Should named queries be checked on startup?- Parameters:
enabled-trueindicates that they should;falseindicates they should not.- Returns:
this, for method chaining- See Also:
-
applySecondLevelCacheSupport
Should second level caching support be enabled?- Parameters:
enabled-trueindicates we should enable the use of second level caching;falseindicates 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-trueindicates we should enable the use of second level query caching;falseindicates we should disable the use of second level query caching.- Returns:
this, for method chaining- See Also:
-
applyQueryCacheLayout
Specifies the defaultCacheLayoutto 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- TheTimestampsCacheFactoryto 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-trueindicates Hibernate should first check whether data exists and only push to the cache if it does not already exist.falseindicates 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-trueindicates that structured (human-readable) cache entries should be used;falseindicates 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-trueindicates 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-trueindicates 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:
-
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-trueto enable this support,falseto disable it- Returns:
this, for method chaining- See Also:
-
applyGetGeneratedKeysSupport
Should JDBCStatement.getGeneratedKeys()feature be used for retrieval of *insert-generated* ids?- Parameters:
enabled-trueindicates we should use JDBC getGeneratedKeys support;falseindicates 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
- See Also:
-
applySqlComments
Should Hibernate apply comments to SQL it generates?- Parameters:
enabled-trueindicates comments should be applied;falseindicates not.- Returns:
this, for method chaining- See Also:
-
applySqlFunction
SessionFactoryBuilder applySqlFunction(String registrationName, SqmFunctionDescriptor functionDescriptor) Register aSQL functionwith 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-truecollections should be included,falsethey should not. Default istrue.- Returns:
this, for method chaining
-
allowOutOfTransactionUpdateOperations
- See Also:
-
enableReleaseResourcesOnCloseEnabled
@Deprecated(since="7.0", forRemoval=true) SessionFactoryBuilder enableReleaseResourcesOnCloseEnabled(boolean enable) Deprecated, for removal: This API element is subject to removal in a future version.since "hibernate.discard_pc_on_close" is deprecatedShould resources held by anEntityManagerbe released immediately on close?The other option is to release them as part of an after transaction callback.
-
enableJpaQueryCompliance
- See Also:
-
enableJpaOrderByMappingCompliance
- See Also:
-
enableJpaTransactionCompliance
- See Also:
-
enableJpaCascadeCompliance
@Deprecated(since="7.0", forRemoval=true) SessionFactoryBuilder enableJpaCascadeCompliance(boolean enabled) Deprecated, for removal: This API element is subject to removal in a future version.No longer has any effect.- See Also:
-
enableJpaClosedCompliance
- See Also:
-
applyJsonFormatMapper
Specifies aformat mapperto use for serialization/deserialization of JSON properties.- Parameters:
jsonFormatMapper- TheFormatMapperto use.- Returns:
this, for method chaining- See Also:
-
applyXmlFormatMapper
Specifies aformat mapperto use for serialization/deserialization of XML properties.- Parameters:
xmlFormatMapper- TheFormatMapperto use.- Returns:
this, for method chaining- See Also:
-
build
SessionFactory build()After all options have been set, build the SessionFactory.- Returns:
- The built SessionFactory.
-