Class HibernatePersistenceConfiguration
- All Implemented Interfaces:
Persistence.BeanManagementProperties, Persistence.CacheProperties, Persistence.ConnectionProperties, Persistence.DatabaseProperties, Persistence.JdbcProperties, Persistence.SchemaManagementProperties, Persistence.ValidationProperties
PersistenceConfiguration
with operations specific to Hibernate.
An instance of Configuration may be obtained simply by
instantiation,
and may be used to aggregate:
- configuration properties from various sources, and
- entity O/R mappings, defined in either annotated classes, or XML mapping documents.
Standard JPA configuration properties are enumerated by the supertype
PersistenceConfiguration. All configuration properties understood
by Hibernate are enumerated by AvailableSettings.
SessionFactory factory = new HibernatePersistenceConfiguration()
// scan classes for mapping annotations
.managedClasses(Item.class, Bid.class, User.class)
// set a configuration property
.setProperty(PersistenceConfiguration.JDBC_DATASOURCE,
"java:comp/env/jdbc/test")
.buildSessionFactory();
When instantiated, an instance of
HibernatePersistenceConfiguration has its properties initially
populated from the environment,
including:
- JVM system properties, and
- properties specified in
hibernate.properties.
When a root URL is supplied, or when at least
one JAR file URL is supplied, and when
hibernate-scan-jandex or some other service implementing
ScanningProvider is available,
the given URLs are scanned for entity classes, embeddable classes,
mapped superclasses, converters, and XML mappings, alleviating the
need to call managedClass(Class) or mappingFile(String).
- Since:
- 7.0
- API Note:
- The specification explicitly encourages implementors to extend
PersistenceConfigurationto accommodate vendor-specific extensions in a more typesafe way. Of course, programs which desire configuration logic to be portable between JPA providers should usePersistenceConfigurationdirectly.
-
Field Summary
Fields inherited from interface Persistence.BeanManagementProperties
BEAN_MANAGERFields inherited from interface Persistence.CacheProperties
CACHE_MODEFields inherited from interface Persistence.ConnectionProperties
JDBC_DATASOURCE, JDBC_DRIVER, JDBC_PASSWORD, JDBC_URL, JDBC_USERFields inherited from interface Persistence.DatabaseProperties
DATABASE_MAJOR_VERSION, DATABASE_MINOR_VERSION, DATABASE_PRODUCT_NAMEFields inherited from interface Persistence.JdbcProperties
JDBC_BATCH_SIZE, JDBC_FETCH_SIZE, LOCK_TIMEOUT, QUERY_TIMEOUTFields inherited from interface Persistence.SchemaManagementProperties
SCHEMAGEN_CONNECTION, SCHEMAGEN_CREATE_SCHEMAS, SCHEMAGEN_CREATE_SCRIPT_SOURCE, SCHEMAGEN_CREATE_SOURCE, SCHEMAGEN_CREATE_TARGET, SCHEMAGEN_DATABASE_ACTION, SCHEMAGEN_DROP_SCRIPT_SOURCE, SCHEMAGEN_DROP_SOURCE, SCHEMAGEN_DROP_TARGET, SCHEMAGEN_LOAD_SCRIPT_SOURCE, SCHEMAGEN_SCRIPTS_ACTIONFields inherited from interface Persistence.ValidationProperties
VALIDATION_FACTORY, VALIDATION_GROUP_PRE_DELETE, VALIDATION_GROUP_PRE_INSERT, VALIDATION_GROUP_PRE_MERGE, VALIDATION_GROUP_PRE_PERSIST, VALIDATION_GROUP_PRE_REMOVE, VALIDATION_GROUP_PRE_UPDATE, VALIDATION_GROUP_PRE_UPSERT, VALIDATION_MODE -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new empty configuration.HibernatePersistenceConfiguration(String name, Class<?> classFromRootUrl) Create a new empty configuration with the root URL inferred from the given class file and used for entity discovery via scanning.HibernatePersistenceConfiguration(String name, URL rootURL) Create a new empty configuration with a given root URL used for entity discovery via scanning. -
Method Summary
Modifier and TypeMethodDescriptioncaching(CachingType type) Enable or disable the second-level and query caches.cachingAccessType(AccessType type) If data caching is enabled, configure the type of concurrency access that should be applied if not explicitly specified on a cache region.cachingCompliance(boolean enabled) Specifies whether Hibernate will strictly adhere to compliance with Jakarta Persistence for handling of proxies.closedCompliance(boolean enabled) Specifies whether Hibernate will strictly adhere to compliance with Jakarta Persistence for handling around calls to EntityHandler.close(), EntityHandler.isOpen(), EntityManagerFactory.close() and EntityManagerFactory.isOpen()collectStatistics(boolean enabled) Configures whether Hibernate should collect Statistics.Create a newSessionFactorybased on this configuration.defaultCatalog(String catalogName) Configure a default catalog name to be used for database objects (tables, sequences, etc) which do not explicitly specify one.defaultSchema(String schemaName) Configure a default schema name to be used for database objects (tables, sequences, etc) which do not explicitly specify one.defaultToOneFetchType(FetchType defaultToOneFetchType) globalGeneratorCompliance(boolean enabled) Specifies whether Hibernate will strictly adhere to compliance with Jakarta Persistence for in terms of collecting all named value generators globally, regardless of location.jarFileUrl(Class<?> classFromJarFile) Locates the jar file in which the given class is located and adds its URL as a JAR file.jarFileUrl(URL url) Add the specified URL as a JAR file.URLs of JAR files.jarFileUrls(Class<?>... classesFromJarFiles) Locates the jar file in which the given class is located and adds its URL as a JAR file.jarFileUrls(URL... urls) Add the specified URLs as JAR files.jarFileUrls(Collection<URL> urls) Add the specified URLs as JAR files.jdbcAutocommit(boolean autocommit) The JDBC autocommit mode for pooled connections.jdbcCredentials(String username, String password) Username and password for JDBC authentication.jdbcDriver(String driverName) JDBC driver class name.jdbcPassword(String password) Password for JDBC authentication.jdbcPoolSize(int poolSize) The JDBC connection pool size.jdbcTransactionIsolation(int isolationLevel) The JDBC transaction isolation level.JDBC URL.jdbcUsername(String username) Username for JDBC authentication.jtaDataSource(String dataSourceJndiName) loadByIdCompliance(boolean enabled) Specifies whether Hibernate will strictly adhere to compliance with Jakarta Persistence for the allowed type of identifier value passed toEntityManager.getReference(Class, Object)andEntityManager.find(Class, Object, Map)managedClass(Class<?> managedClass) managedClasses(Class<?>... managedClasses) Add the specified classes as managed classes.managedClasses(Collection<Class<?>> managedClasses) Add the specified classes as managed classes.mappingFile(String name) mappingFiles(String... names) Add the specified resource names as mapping files.mappingFiles(Collection<String> names) Add the specified resource names as mapping files.nationalizedCharacterData(boolean enabled) Configure a default schema name to be used for database objects (tables, sequences, etc) which do not explicitly specify one.nonJtaDataSource(String dataSourceJndiName) orderByMappingCompliance(boolean enabled) Specifies whether Hibernate will strictly adhere to compliance with Jakarta Persistence for the interpretation ofOrderBy.properties(Map<String, ?> properties) proxyCompliance(boolean enabled) Specifies whether Hibernate will strictly adhere to compliance with Jakarta Persistence for handling of proxies.queryCompliance(boolean enabled) Specifies whether Hibernate will strictly adhere to compliance with Jakarta Persistence for all aspects of Query handling.rootUrl()Root URL of the persistence unit.schemaToolingAction(Action action) Specify the action to take in terms of automatic database schema tooling.sharedCacheMode(SharedCacheMode sharedCacheMode) showSql(boolean showSql, boolean formatSql, boolean highlightSql) Enables SQL logging to the console.statementInspector(Class<? extends StatementInspector> inspectorImpl) Specify a StatementInspector to be applied to all Sessions/EntityManagersstatementInspector(StatementInspector inspector) Specify a StatementInspector to be applied to all Sessions/EntityManagersstatementObserver(Class<? extends StatementObserver> statementObserverImpl) Applies a StatementObserver to the EntityManagerFactory being built.statementObserver(StatementObserver statementObserver) Applies a StatementObserver to the EntityManagerFactory being built.transactionCompliance(boolean enabled) Specifies whether Hibernate will strictly adhere to compliance with Jakarta Persistence for all aspects of transaction handling.transactionType(PersistenceUnitTransactionType transactionType) validationMode(ValidationMode validationMode) xmlMappings(boolean enabled) Configures whether Hibernate should process XML mappings (orm.xmlfiles).xmlValidation(boolean enabled) Configures whether Hibernate should validate (via schema descriptor) XML files.
-
Constructor Details
-
HibernatePersistenceConfiguration
Create a new empty configuration. An empty configuration does not typically hold enough information for successful invocation ofcreateEntityManagerFactory().- Parameters:
name- the name of the persistence unit, which may be used by the persistence provider for logging and error reporting
-
HibernatePersistenceConfiguration
Create a new empty configuration with a given root URL used for entity discovery via scanning.The module
hibernate-scan-jandexmust be added as a dependency, or some other implementation of the serviceScanningProvidermust be made available.- Parameters:
name- the name of the persistence unit, which may be used by the persistence provider for logging and error reportingrootURL- the root URL of the persistence unit- Since:
- 7.1
-
HibernatePersistenceConfiguration
Create a new empty configuration with the root URL inferred from the given class file and used for entity discovery via scanning.The module
hibernate-scan-jandexmust be added as a dependency, or some other implementation of the serviceScanningProvidermust be made available.- Parameters:
name- the name of the persistence unit, which may be used by the persistence provider for logging and error reportingclassFromRootUrl- a class loaded from the root URL of the persistence unit- Since:
- 7.1
-
-
Method Details
-
createEntityManagerFactory
Create a newSessionFactorybased on this configuration.- Overrides:
createEntityManagerFactoryin classPersistenceConfiguration
-
jdbcDriver
JDBC driver class name. This setting is ignored when Hibernate is configured to obtain connections from aDataSource.- See Also:
-
jdbcUrl
JDBC URL. This setting is ignored when Hibernate is configured to obtain connections from aDataSource.- See Also:
-
jdbcUsername
Username for JDBC authentication.- See Also:
-
jdbcPassword
Password for JDBC authentication.- See Also:
-
jdbcCredentials
Username and password for JDBC authentication.- See Also:
-
jdbcPoolSize
The JDBC connection pool size. This setting is ignored when Hibernate is configured to obtain connections from aDataSource.- See Also:
-
jdbcAutocommit
The JDBC autocommit mode for pooled connections. This setting is ignored when Hibernate is configured to obtain connections from aDataSource.- See Also:
-
jdbcTransactionIsolation
The JDBC transaction isolation level. This setting is ignored when Hibernate is configured to obtain connections from aDataSource.Possible values are enumerated by
Connection:Connection.TRANSACTION_READ_UNCOMMITTED,Connection.TRANSACTION_READ_COMMITTED,Connection.TRANSACTION_REPEATABLE_READ, andConnection.TRANSACTION_SERIALIZABLE.- See Also:
-
showSql
@Nonnull public HibernatePersistenceConfiguration showSql(boolean showSql, boolean formatSql, boolean highlightSql) Enables SQL logging to the console.Sets "hibernate.show_sql", "hibernate.format_sql", and "hibernate.highlight_sql".
- Parameters:
showSql- should SQL be logged to console?formatSql- should logged SQL be formattedhighlightSql- should logged SQL be highlighted with pretty colors
-
queryCompliance
Specifies whether Hibernate will strictly adhere to compliance with Jakarta Persistence for all aspects of Query handling.- See Also:
-
transactionCompliance
Specifies whether Hibernate will strictly adhere to compliance with Jakarta Persistence for all aspects of transaction handling.- See Also:
-
closedCompliance
Specifies whether Hibernate will strictly adhere to compliance with Jakarta Persistence for handling around calls to EntityHandler.close(), EntityHandler.isOpen(), EntityManagerFactory.close() and EntityManagerFactory.isOpen()- See Also:
-
proxyCompliance
Specifies whether Hibernate will strictly adhere to compliance with Jakarta Persistence for handling of proxies.- See Also:
-
cachingCompliance
Specifies whether Hibernate will strictly adhere to compliance with Jakarta Persistence for handling of proxies.- See Also:
-
globalGeneratorCompliance
Specifies whether Hibernate will strictly adhere to compliance with Jakarta Persistence for in terms of collecting all named value generators globally, regardless of location.- See Also:
-
orderByMappingCompliance
Specifies whether Hibernate will strictly adhere to compliance with Jakarta Persistence for the interpretation ofOrderBy.- See Also:
-
loadByIdCompliance
Specifies whether Hibernate will strictly adhere to compliance with Jakarta Persistence for the allowed type of identifier value passed toEntityManager.getReference(Class, Object)andEntityManager.find(Class, Object, Map)- See Also:
-
caching
Enable or disable the second-level and query caches. -
cachingAccessType
If data caching is enabled, configure the type of concurrency access that should be applied if not explicitly specified on a cache region.- See Also:
-
statementInspector
@Nonnull public HibernatePersistenceConfiguration statementInspector(Class<? extends StatementInspector> inspectorImpl) Specify a StatementInspector to be applied to all Sessions/EntityManagers- See Also:
-
statementInspector
Specify a StatementInspector to be applied to all Sessions/EntityManagers- See Also:
-
defaultCatalog
Configure a default catalog name to be used for database objects (tables, sequences, etc) which do not explicitly specify one.- See Also:
-
defaultSchema
Configure a default schema name to be used for database objects (tables, sequences, etc) which do not explicitly specify one.- See Also:
-
nationalizedCharacterData
Configure a default schema name to be used for database objects (tables, sequences, etc) which do not explicitly specify one.- See Also:
-
xmlMappings
Configures whether Hibernate should process XML mappings (orm.xmlfiles).- See Also:
-
xmlValidation
Configures whether Hibernate should validate (via schema descriptor) XML files.- See Also:
-
collectStatistics
Configures whether Hibernate should collect Statistics.- See Also:
-
managedClasses
@Nonnull public HibernatePersistenceConfiguration managedClasses(@Nonnull Class<?>... managedClasses) Add the specified classes as managed classes.- See Also:
-
managedClasses
@Nonnull public HibernatePersistenceConfiguration managedClasses(@Nonnull Collection<Class<?>> managedClasses) Add the specified classes as managed classes.- See Also:
-
mappingFiles
Add the specified resource names as mapping files.- See Also:
-
mappingFiles
Add the specified resource names as mapping files.- See Also:
-
rootUrl
Root URL of the persistence unit. When entity discovery is enabled, this root URL will be scanned for entities.- Since:
- 7.1
- See Also:
-
jarFileUrls
URLs of JAR files. When entity discovery is enabled, the JAR files will be scanned for entities.- Since:
- 7.1
- See Also:
-
jarFileUrl
Add the specified URL as a JAR file.- Since:
- 7.1
- See Also:
-
jarFileUrls
Add the specified URLs as JAR files.- Since:
- 7.1
- See Also:
-
jarFileUrls
Add the specified URLs as JAR files.- Since:
- 7.1
- See Also:
-
jarFileUrl
Locates the jar file in which the given class is located and adds its URL as a JAR file.- Since:
- 8.0
- See Also:
-
jarFileUrls
@Nonnull public HibernatePersistenceConfiguration jarFileUrls(@Nonnull Class<?>... classesFromJarFiles) Locates the jar file in which the given class is located and adds its URL as a JAR file.- Since:
- 8.0
- See Also:
-
schemaToolingAction
Specify the action to take in terms of automatic database schema tooling.- See Also:
- API Note:
- This only controls tooling as exported directly to the database. To output tooling commands to scripts, use config properties instead with appropriate settings.
-
statementObserver
@Nonnull public HibernatePersistenceConfiguration statementObserver(StatementObserver statementObserver) Applies a StatementObserver to the EntityManagerFactory being built.- See Also:
-
statementObserver
@Nonnull public HibernatePersistenceConfiguration statementObserver(Class<? extends StatementObserver> statementObserverImpl) Applies a StatementObserver to the EntityManagerFactory being built.- See Also:
-
provider
- Overrides:
providerin classPersistenceConfiguration
-
jtaDataSource
@Nonnull public HibernatePersistenceConfiguration jtaDataSource(@Nullable String dataSourceJndiName) - Overrides:
jtaDataSourcein classPersistenceConfiguration
-
nonJtaDataSource
@Nonnull public HibernatePersistenceConfiguration nonJtaDataSource(@Nullable String dataSourceJndiName) - Overrides:
nonJtaDataSourcein classPersistenceConfiguration
-
managedClass
- Overrides:
managedClassin classPersistenceConfiguration
-
mappingFile
- Overrides:
mappingFilein classPersistenceConfiguration
-
transactionType
@Nonnull public HibernatePersistenceConfiguration transactionType(@Nonnull PersistenceUnitTransactionType transactionType) - Overrides:
transactionTypein classPersistenceConfiguration
-
validationMode
@Nonnull public HibernatePersistenceConfiguration validationMode(@Nonnull ValidationMode validationMode) - Overrides:
validationModein classPersistenceConfiguration
-
defaultToOneFetchType
@Nonnull public HibernatePersistenceConfiguration defaultToOneFetchType(@Nonnull FetchType defaultToOneFetchType) - Overrides:
defaultToOneFetchTypein classPersistenceConfiguration
-
schemaManagementDatabaseAction
@Nonnull public HibernatePersistenceConfiguration schemaManagementDatabaseAction(@Nonnull SchemaManagementAction action) - Overrides:
schemaManagementDatabaseActionin classPersistenceConfiguration
-
schemaManagementScriptsAction
@Nonnull public HibernatePersistenceConfiguration schemaManagementScriptsAction(@Nonnull SchemaManagementAction action) - Overrides:
schemaManagementScriptsActionin classPersistenceConfiguration
-
property
@Nonnull public HibernatePersistenceConfiguration property(@Nonnull String name, @Nullable Object value) - Overrides:
propertyin classPersistenceConfiguration
-
properties
- Overrides:
propertiesin classPersistenceConfiguration
-