Class HibernatePersistenceConfiguration
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
ScannerFactory
is available,
the given URLs are scanned for entity classes, embeddable classes,
mapped superclasses, converters, and XML mappings, alleviating the
need to call managedClass(java.lang.Class<?>)
or mappingFile(java.lang.String)
.
- Since:
- 7.0
- API Note:
- The specification explicitly encourages implementors to extend
PersistenceConfiguration
to accommodate vendor-specific extensions in a more typesafe way. Of course, programs which desire configuration logic to be portable between JPA providers should usePersistenceConfiguration
directly.
-
Field Summary
Fields inherited from class jakarta.persistence.PersistenceConfiguration
CACHE_MODE, JDBC_DATASOURCE, JDBC_DRIVER, JDBC_PASSWORD, JDBC_URL, JDBC_USER, LOCK_TIMEOUT, QUERY_TIMEOUT, SCHEMAGEN_CREATE_SCRIPT_SOURCE, SCHEMAGEN_CREATE_SOURCE, SCHEMAGEN_CREATE_TARGET, SCHEMAGEN_DATABASE_ACTION, SCHEMAGEN_DROP_SCRIPT_SOURCE, SCHEMAGEN_DROP_SOURCE, SCHEMAGEN_DROP_TARGET, SCHEMAGEN_SCRIPTS_ACTION, VALIDATION_FACTORY, VALIDATION_GROUP_PRE_PERSIST, VALIDATION_GROUP_PRE_REMOVE, VALIDATION_GROUP_PRE_UPDATE
-
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 EntityManager.close(), EntityManager.isOpen(), EntityManagerFactory.close() and EntityManagerFactory.isOpen()collectStatistics
(boolean enabled) Configures whether Hibernate should collect Statistics.Create a newSessionFactory
based 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.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
(URL url) Add the specified URL as a JAR file.URLs of JAR files.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(java.lang.Class<T>, java.lang.Object)
andEntityManager.find(java.lang.Class<T>, java.lang.Object)
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/EntityManagerstransactionCompliance
(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.xml
files).xmlValidation
(boolean enabled) Configures whether Hibernate should validate (via schema descriptor) XML files.Methods inherited from class jakarta.persistence.PersistenceConfiguration
jtaDataSource, managedClasses, mappingFiles, name, nonJtaDataSource, properties, provider, sharedCacheMode, transactionType, validationMode
-
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-jandex
must be added as a dependency, or some other implementation of the serviceScannerFactory
must 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-jandex
must be added as a dependency, or some other implementation of the serviceScannerFactory
must 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 newSessionFactory
based on this configuration.- Overrides:
createEntityManagerFactory
in 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
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 EntityManager.close(), EntityManager.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(java.lang.Class<T>, java.lang.Object)
andEntityManager.find(java.lang.Class<T>, java.lang.Object)
- 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
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.xml
files).- 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
Add the specified classes as managed classes.- See Also:
-
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:
-
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:
-
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.
-
provider
- Overrides:
provider
in classPersistenceConfiguration
-
jtaDataSource
- Overrides:
jtaDataSource
in classPersistenceConfiguration
-
nonJtaDataSource
- Overrides:
nonJtaDataSource
in classPersistenceConfiguration
-
managedClass
- Overrides:
managedClass
in classPersistenceConfiguration
-
mappingFile
- Overrides:
mappingFile
in classPersistenceConfiguration
-
transactionType
public HibernatePersistenceConfiguration transactionType(PersistenceUnitTransactionType transactionType) - Overrides:
transactionType
in classPersistenceConfiguration
-
validationMode
- Overrides:
validationMode
in classPersistenceConfiguration
-
property
- Overrides:
property
in classPersistenceConfiguration
-
properties
- Overrides:
properties
in classPersistenceConfiguration
-
jarFileUrls
URLs of JAR files. When entity discovery is enabled, the JAR files will be scanned for entities.- Since:
- 7.1
- 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:
-