Interface SessionFactoryBuilder
-
- All Known Subinterfaces:
SessionFactoryBuilderImplementor
- All Known Implementing Classes:
AbstractDelegatingSessionFactoryBuilder
,AbstractDelegatingSessionFactoryBuilderImplementor
,SessionFactoryBuilderImpl
public interface SessionFactoryBuilder
The contract for building aSessionFactory
given a specified set of options.- Since:
- 5.0
- See Also:
Metadata.getSessionFactoryBuilder()
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description SessionFactoryBuilder
addEntityNameResolver(EntityNameResolver... entityNameResolvers)
Specifies one or more entity name resolvers.SessionFactoryBuilder
addSessionFactoryObservers(SessionFactoryObserver... observers)
Specifies one or more observers.SessionFactoryBuilder
allowOutOfTransactionUpdateOperations(boolean allow)
SessionFactoryBuilder
applyAutoClosing(boolean enabled)
Specifies whetherSession
s should be automatically closed at the end of the transaction.SessionFactoryBuilder
applyAutoFlushing(boolean enabled)
Applies whetherSession
s should be automatically flushed at the end of the transaction.SessionFactoryBuilder
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).SessionFactoryBuilder
applyBatchFetchStyle(BatchFetchStyle style)
Deprecated.: an appropriate style is selectedSessionFactoryBuilder
applyBeanManager(Object beanManager)
Specifies a CDIBeanManager
.SessionFactoryBuilder
applyCacheRegionPrefix(String prefix)
Specify a prefix to prepended to all cache region names.SessionFactoryBuilder
applyCollectionsInDefaultFetchGroup(boolean enabled)
Should collections be included in the default fetch group when bytecode enhancement is used?SessionFactoryBuilder
applyConnectionHandlingMode(PhysicalConnectionHandlingMode connectionHandlingMode)
Specifies the connection handling mode for JDBC connections.SessionFactoryBuilder
applyConnectionProviderDisablesAutoCommit(boolean providerDisablesAutoCommit)
SessionFactoryBuilder
applyCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver<?> resolver)
Specifies aCurrentTenantIdentifierResolver
that is responsible for resolving the current tenant identifier.SessionFactoryBuilder
applyCustomEntityDirtinessStrategy(CustomEntityDirtinessStrategy strategy)
Specifies aCustomEntityDirtinessStrategy
.SessionFactoryBuilder
applyDefaultBatchFetchSize(int size)
Specifies a default batch fetch size for all entities and collections which do not otherwise specify a batch fetch size.SessionFactoryBuilder
applyDefaultNullPrecedence(NullPrecedence nullPrecedence)
Apply a null precedence,NULLS FIRST
orNULLS LAST
, toorder by
clauses rendered in SQL queries.SessionFactoryBuilder
applyDelayedEntityLoaderCreations(boolean delay)
Should entity loaders be generated immediately? Or should the creation be delayed until first need?SessionFactoryBuilder
applyDirectReferenceCaching(boolean enabled)
Generally, Hibernate will extract the information from an entity and put that extracted information into the second-level cache.SessionFactoryBuilder
applyEntityNotFoundDelegate(EntityNotFoundDelegate entityNotFoundDelegate)
Specifies anEntityNotFoundDelegate
.SessionFactoryBuilder
applyGetGeneratedKeysSupport(boolean enabled)
Should JDBCStatement.getGeneratedKeys()
feature be used for retrieval of *insert-generated* ids?SessionFactoryBuilder
applyIdentifierRollbackSupport(boolean enabled)
Should the generated identifier be "unset" when an entity is deleted?SessionFactoryBuilder
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)
.SessionFactoryBuilder
applyJdbcBatchingForVersionedEntities(boolean enabled)
This setting controls whether versioned entities will be included in JDBC batching.SessionFactoryBuilder
applyJdbcBatchSize(int size)
Specifies the maximum number of statements to batch together in a JDBC batch for insert, update and delete operations.SessionFactoryBuilder
applyJdbcFetchSize(int size)
Apply a fetch size to the JDBC driver for fetching results.SessionFactoryBuilder
applyJsonFormatMapper(FormatMapper jsonFormatMapper)
Specifies aformat mapper
to use for serialization/deserialization of JSON properties.SessionFactoryBuilder
applyJtaTrackingByThread(boolean enabled)
If using the built-in JTA-basedTransactionCoordinator
orTransactionCoordinatorBuilder
, should it track JTA transactions by thread in an attempt to detect timeouts?SessionFactoryBuilder
applyLazyInitializationOutsideTransaction(boolean enabled)
Should the application be allowed to initialize uninitialized lazy state outside the bounds of a transaction?SessionFactoryBuilder
applyMaximumFetchDepth(int depth)
Apply a limit to the depth Hibernate will use for outer joins.SessionFactoryBuilder
applyMinimalPutsForCaching(boolean enabled)
By default, Hibernate will always just push data into the cache without first checking if that data already exists.SessionFactoryBuilder
applyMultiTenancy(boolean enabled)
Specifies whether multitenancy is enabled via use of aMultiTenantConnectionProvider
.SessionFactoryBuilder
applyName(String sessionFactoryName)
Specifies a name for theSessionFactory
.SessionFactoryBuilder
applyNameAsJndiName(boolean isJndiName)
Specifies that theSessionFactory
should be registered in JNDI, under the name specified usingapplyName(String)
.SessionFactoryBuilder
applyNamedQueryCheckingOnStartup(boolean enabled)
Should named queries be checked on startup?SessionFactoryBuilder
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?SessionFactoryBuilder
applyOrderingOfInserts(boolean enabled)
Specify whether ordering of inserts should be enabled.SessionFactoryBuilder
applyOrderingOfUpdates(boolean enabled)
Specify whether ordering of updates should be enabled.SessionFactoryBuilder
applyPreferUserTransactions(boolean preferUserTransactions)
If using the built-in JTA-basedTransactionCoordinator
orTransactionCoordinatorBuilder
, should it prefer to useUserTransaction
in preference toTransaction
?SessionFactoryBuilder
applyQueryCacheLayout(CacheLayout cacheLayout)
Specifies the defaultCacheLayout
to use for query cache entries.SessionFactoryBuilder
applyQueryCacheSupport(boolean enabled)
Should second level query caching support be enabled?SessionFactoryBuilder
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.SessionFactoryBuilder
applySecondLevelCacheSupport(boolean enabled)
Should second level caching support be enabled?SessionFactoryBuilder
applySqlComments(boolean enabled)
Should Hibernate apply comments to SQL it generates?SessionFactoryBuilder
applySqlFunction(String registrationName, SqmFunctionDescriptor functionDescriptor)
Register aSQL function
with the underlyingSqmFunctionRegistry
.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)
.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)
.SessionFactoryBuilder
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)
SessionFactoryBuilder
applyStatisticsSupport(boolean enabled)
Specifies whether statistics gathering is enabled.SessionFactoryBuilder
applyStructuredCacheEntries(boolean enabled)
By default, Hibernate stores data in the cache in its own optimized format.SessionFactoryBuilder
applySubselectFetchEnabled(boolean enabled)
Enable the use of subselect fetching.SessionFactoryBuilder
applyTempTableDdlTransactionHandling(TempTableDdlTransactionHandling handling)
Specifies how temporary tables should be created or dropped with respect to transaction handling.SessionFactoryBuilder
applyTimestampsCacheFactory(TimestampsCacheFactory factory)
Specifies aTimestampsCacheFactory
.SessionFactoryBuilder
applyValidatorFactory(Object validatorFactory)
Specifies a Bean ValidationValidatorFactory
.SessionFactoryBuilder
applyXmlFormatMapper(FormatMapper xmlFormatMapper)
Specifies aformat mapper
to use for serialization/deserialization of XML properties.SessionFactory
build()
After all options have been set, build the SessionFactory.SessionFactoryBuilder
enableJpaCascadeCompliance(boolean enabled)
SessionFactoryBuilder
enableJpaClosedCompliance(boolean enabled)
SessionFactoryBuilder
enableJpaListCompliance(boolean enabled)
Deprecated.UseMappingSettings.DEFAULT_LIST_SEMANTICS
insteadSessionFactoryBuilder
enableJpaOrderByMappingCompliance(boolean enabled)
SessionFactoryBuilder
enableJpaQueryCompliance(boolean enabled)
SessionFactoryBuilder
enableJpaTransactionCompliance(boolean enabled)
SessionFactoryBuilder
enableReleaseResourcesOnCloseEnabled(boolean enable)
Should resources held by anEntityManager
be released immediately on close?
-
-
-
Method Detail
-
applyValidatorFactory
SessionFactoryBuilder applyValidatorFactory(Object validatorFactory)
Specifies a Bean ValidationValidatorFactory
.- Parameters:
validatorFactory
- The Bean ValidationValidatorFactory
to use- Returns:
this
, for method chaining- See Also:
ValidationSettings.JAKARTA_VALIDATION_FACTORY
- API Note:
- De-typed to avoid a hard dependency on the Bean Validation jar
-
applyBeanManager
SessionFactoryBuilder applyBeanManager(Object beanManager)
Specifies a CDIBeanManager
.- Parameters:
beanManager
- The CDIBeanManager
to use- Returns:
this
, for method chaining- See Also:
ManagedBeanSettings.JAKARTA_CDI_BEAN_MANAGER
- API Note:
- De-typed to avoid a hard dependency on the CDI jar
-
applyName
SessionFactoryBuilder applyName(String sessionFactoryName)
Specifies a name for theSessionFactory
.- Parameters:
sessionFactoryName
- The name to use- Returns:
this
, for method chaining- See Also:
PersistenceSettings.SESSION_FACTORY_NAME
-
applyNameAsJndiName
SessionFactoryBuilder applyNameAsJndiName(boolean isJndiName)
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:
PersistenceSettings.SESSION_FACTORY_NAME_IS_JNDI
-
applyAutoClosing
SessionFactoryBuilder applyAutoClosing(boolean enabled)
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:
TransactionSettings.AUTO_CLOSE_SESSION
-
applyAutoFlushing
SessionFactoryBuilder applyAutoFlushing(boolean enabled)
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:
TransactionSettings.FLUSH_BEFORE_COMPLETION
-
applyStatisticsSupport
SessionFactoryBuilder applyStatisticsSupport(boolean enabled)
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:
StatisticsSettings.GENERATE_STATISTICS
-
applyInterceptor
SessionFactoryBuilder 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)
.- Parameters:
interceptor
- The interceptor- Returns:
this
, for method chaining- See Also:
SessionEventSettings.INTERCEPTOR
-
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:
SessionEventSettings.SESSION_SCOPED_INTERCEPTOR
-
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:
SessionEventSettings.SESSION_SCOPED_INTERCEPTOR
-
applyStatementInspector
SessionFactoryBuilder 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)
- Parameters:
statementInspector
- The StatementInspector- Returns:
this
, for method chaining- See Also:
JdbcSettings.STATEMENT_INSPECTOR
-
addSessionFactoryObservers
SessionFactoryBuilder addSessionFactoryObservers(SessionFactoryObserver... observers)
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:
PersistenceSettings.SESSION_FACTORY_OBSERVER
-
applyCustomEntityDirtinessStrategy
SessionFactoryBuilder applyCustomEntityDirtinessStrategy(CustomEntityDirtinessStrategy strategy)
Specifies aCustomEntityDirtinessStrategy
.- Parameters:
strategy
- The custom strategy to be used.- Returns:
this
, for method chaining- See Also:
AvailableSettings.CUSTOM_ENTITY_DIRTINESS_STRATEGY
-
addEntityNameResolver
SessionFactoryBuilder addEntityNameResolver(EntityNameResolver... entityNameResolvers)
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
SessionFactoryBuilder applyEntityNotFoundDelegate(EntityNotFoundDelegate entityNotFoundDelegate)
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
SessionFactoryBuilder applyIdentifierRollbackSupport(boolean enabled)
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:
AvailableSettings.USE_IDENTIFIER_ROLLBACK
-
applyNullabilityChecking
SessionFactoryBuilder 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?- Parameters:
enabled
-true
indicates that Hibernate should perform nullness checking;false
indicates it should not.- Returns:
this
, for method chaining- See Also:
ValidationSettings.CHECK_NULLABILITY
-
applyLazyInitializationOutsideTransaction
SessionFactoryBuilder applyLazyInitializationOutsideTransaction(boolean enabled)
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:
TransactionSettings.ENABLE_LAZY_LOAD_NO_TRANS
-
applyTempTableDdlTransactionHandling
SessionFactoryBuilder applyTempTableDdlTransactionHandling(TempTableDdlTransactionHandling handling)
Specifies how temporary tables should be created or dropped with respect to transaction handling.- See Also:
TempTableDdlTransactionHandling
-
applyBatchFetchStyle
@Deprecated(since="6.0") SessionFactoryBuilder applyBatchFetchStyle(BatchFetchStyle style)
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:
FetchSettings.BATCH_FETCH_STYLE
-
applyDelayedEntityLoaderCreations
SessionFactoryBuilder applyDelayedEntityLoaderCreations(boolean delay)
Should entity loaders be generated immediately? Or should the creation be delayed until first need?
-
applyDefaultBatchFetchSize
SessionFactoryBuilder applyDefaultBatchFetchSize(int size)
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:
FetchSettings.DEFAULT_BATCH_FETCH_SIZE
-
applyMaximumFetchDepth
SessionFactoryBuilder applyMaximumFetchDepth(int depth)
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:
FetchSettings.MAX_FETCH_DEPTH
-
applySubselectFetchEnabled
SessionFactoryBuilder applySubselectFetchEnabled(boolean enabled)
Enable the use of subselect fetching.- Parameters:
enabled
-true
indicates that subselect fetching is enabled- Returns:
this
, for method chaining- See Also:
FetchSettings.USE_SUBSELECT_FETCH
-
applyDefaultNullPrecedence
SessionFactoryBuilder applyDefaultNullPrecedence(NullPrecedence nullPrecedence)
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:
QuerySettings.DEFAULT_NULL_ORDERING
-
applyOrderingOfInserts
SessionFactoryBuilder applyOrderingOfInserts(boolean enabled)
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:
BatchSettings.ORDER_INSERTS
-
applyOrderingOfUpdates
SessionFactoryBuilder applyOrderingOfUpdates(boolean enabled)
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:
BatchSettings.ORDER_UPDATES
-
applyMultiTenancy
SessionFactoryBuilder applyMultiTenancy(boolean enabled)
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:
MultiTenancySettings.MULTI_TENANT_CONNECTION_PROVIDER
-
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:
MultiTenancySettings.MULTI_TENANT_IDENTIFIER_RESOLVER
-
applyJtaTrackingByThread
SessionFactoryBuilder applyJtaTrackingByThread(boolean enabled)
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:
TransactionSettings.JTA_TRACK_BY_THREAD
-
applyPreferUserTransactions
SessionFactoryBuilder applyPreferUserTransactions(boolean preferUserTransactions)
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:
TransactionSettings.PREFER_USER_TRANSACTION
-
applyNamedQueryCheckingOnStartup
SessionFactoryBuilder applyNamedQueryCheckingOnStartup(boolean enabled)
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:
QuerySettings.QUERY_STARTUP_CHECKING
-
applySecondLevelCacheSupport
SessionFactoryBuilder applySecondLevelCacheSupport(boolean enabled)
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:
CacheSettings.USE_SECOND_LEVEL_CACHE
-
applyQueryCacheSupport
SessionFactoryBuilder applyQueryCacheSupport(boolean enabled)
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:
CacheSettings.USE_QUERY_CACHE
-
applyQueryCacheLayout
@Incubating SessionFactoryBuilder applyQueryCacheLayout(CacheLayout cacheLayout)
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:
CacheSettings.QUERY_CACHE_LAYOUT
-
applyTimestampsCacheFactory
SessionFactoryBuilder applyTimestampsCacheFactory(TimestampsCacheFactory factory)
Specifies aTimestampsCacheFactory
.- Parameters:
factory
- TheTimestampsCacheFactory
to use- Returns:
this
, for method chaining- See Also:
CacheSettings.QUERY_CACHE_FACTORY
-
applyCacheRegionPrefix
SessionFactoryBuilder applyCacheRegionPrefix(String prefix)
Specify a prefix to prepended to all cache region names.- Parameters:
prefix
- The prefix.- Returns:
this
, for method chaining- See Also:
CacheSettings.CACHE_REGION_PREFIX
-
applyMinimalPutsForCaching
SessionFactoryBuilder applyMinimalPutsForCaching(boolean enabled)
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:
CacheSettings.USE_MINIMAL_PUTS
,RegionFactory.isMinimalPutsEnabledByDefault()
-
applyStructuredCacheEntries
SessionFactoryBuilder applyStructuredCacheEntries(boolean enabled)
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:
CacheSettings.USE_STRUCTURED_CACHE
-
applyDirectReferenceCaching
SessionFactoryBuilder applyDirectReferenceCaching(boolean enabled)
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:
CacheSettings.USE_DIRECT_REFERENCE_CACHE_ENTRIES
-
applyAutomaticEvictionOfCollectionCaches
SessionFactoryBuilder 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). 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:
CacheSettings.AUTO_EVICT_COLLECTION_CACHE
-
applyJdbcBatchSize
SessionFactoryBuilder applyJdbcBatchSize(int size)
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:
BatchSettings.STATEMENT_BATCH_SIZE
-
applyJdbcBatchingForVersionedEntities
SessionFactoryBuilder applyJdbcBatchingForVersionedEntities(boolean enabled)
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:
BatchSettings.BATCH_VERSIONED_DATA
-
applyScrollableResultsSupport
SessionFactoryBuilder 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. 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:
JdbcSettings.USE_SCROLLABLE_RESULTSET
-
applyGetGeneratedKeysSupport
SessionFactoryBuilder applyGetGeneratedKeysSupport(boolean enabled)
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:
JdbcSettings.USE_GET_GENERATED_KEYS
-
applyJdbcFetchSize
SessionFactoryBuilder applyJdbcFetchSize(int size)
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:
JdbcSettings.STATEMENT_FETCH_SIZE
,Statement.setFetchSize(int)
-
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:
JdbcSettings.CONNECTION_HANDLING
,PhysicalConnectionHandlingMode
,ConnectionAcquisitionMode
,ConnectionReleaseMode
-
applyConnectionProviderDisablesAutoCommit
SessionFactoryBuilder applyConnectionProviderDisablesAutoCommit(boolean providerDisablesAutoCommit)
-
applySqlComments
SessionFactoryBuilder applySqlComments(boolean enabled)
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:
JdbcSettings.USE_SQL_COMMENTS
-
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
SessionFactoryBuilder applyCollectionsInDefaultFetchGroup(boolean enabled)
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
SessionFactoryBuilder allowOutOfTransactionUpdateOperations(boolean allow)
-
enableReleaseResourcesOnCloseEnabled
SessionFactoryBuilder enableReleaseResourcesOnCloseEnabled(boolean enable)
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
SessionFactoryBuilder enableJpaQueryCompliance(boolean enabled)
-
enableJpaOrderByMappingCompliance
SessionFactoryBuilder enableJpaOrderByMappingCompliance(boolean enabled)
-
enableJpaTransactionCompliance
SessionFactoryBuilder enableJpaTransactionCompliance(boolean enabled)
-
enableJpaListCompliance
@Deprecated(since="6.0") SessionFactoryBuilder enableJpaListCompliance(boolean enabled)
Deprecated.UseMappingSettings.DEFAULT_LIST_SEMANTICS
instead
-
enableJpaCascadeCompliance
SessionFactoryBuilder enableJpaCascadeCompliance(boolean enabled)
-
enableJpaClosedCompliance
SessionFactoryBuilder enableJpaClosedCompliance(boolean enabled)
-
applyJsonFormatMapper
@Incubating SessionFactoryBuilder applyJsonFormatMapper(FormatMapper jsonFormatMapper)
Specifies aformat mapper
to use for serialization/deserialization of JSON properties.- Parameters:
jsonFormatMapper
- TheFormatMapper
to use.- Returns:
this
, for method chaining- See Also:
MappingSettings.JSON_FORMAT_MAPPER
-
applyXmlFormatMapper
@Incubating SessionFactoryBuilder applyXmlFormatMapper(FormatMapper xmlFormatMapper)
Specifies aformat mapper
to use for serialization/deserialization of XML properties.- Parameters:
xmlFormatMapper
- TheFormatMapper
to use.- Returns:
this
, for method chaining- See Also:
MappingSettings.XML_FORMAT_MAPPER
-
build
SessionFactory build()
After all options have been set, build the SessionFactory.- Returns:
- The built SessionFactory.
-
-