Top Description Fields Constructors Methods
org.springframework.orm.jpa.vendor

public Class HibernateJpaVendorAdapter

extends AbstractJpaVendorAdapter
Class Inheritance
Imports
java.util.HashMap, .Map, jakarta.persistence.EntityManager, .EntityManagerFactory, jakarta.persistence.spi.PersistenceProvider, .PersistenceUnitInfo, .PersistenceUnitTransactionType, org.hibernate.Session, .SessionFactory, org.hibernate.cfg.AvailableSettings, org.hibernate.dialect.DB2Dialect, .DerbyTenSevenDialect, .H2Dialect, .HANAColumnStoreDialect, .HSQLDialect, .Informix10Dialect, .MySQL57Dialect, .MySQLDialect, .Oracle12cDialect, .OracleDialect, .PostgreSQL95Dialect, .SQLServer2012Dialect, .SQLServerDialect, .SybaseDialect, org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode, org.springframework.lang.Nullable, org.springframework.util.ClassUtils

org.springframework.orm.jpa.JpaVendorAdapter implementation for Hibernate. Compatible with Hibernate ORM 5.5/5.6 as well as 6.0/6.1/6.2/6.3.

Exposes Hibernate's persistence provider and Hibernate's Session as extended EntityManager interface, and adapts AbstractJpaVendorAdapter's common configuration settings. Also supports the detection of annotated packages (through org.springframework.orm.jpa.persistenceunit.SmartPersistenceUnitInfo#getManagedPackages()), e.g. containing Hibernate org.hibernate.annotations.FilterDef annotations, along with Spring-driven entity scanning which requires no persistence.xml (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#setPackagesToScan).

A note about HibernateJpaVendorAdapter vs native Hibernate settings: Some settings on this adapter may conflict with native Hibernate configuration rules or custom Hibernate properties. For example, specify either setDatabase or Hibernate's "hibernate.dialect_resolvers" property, not both. Also, be careful about Hibernate's connection release mode: This adapter prefers ON_CLOSE behavior, aligned with HibernateJpaDialect#setPrepareConnection, at least for non-JTA scenarios; you may override this through corresponding native Hibernate properties.

Authors
Juergen Hoeller, Rod Johnson
Since
2.0
See Also
HibernateJpaDialect

Field Summary

Modifier and TypeField and Description
private final Class<? extends EntityManagerFactory>
private final Class<? extends EntityManager>
private final HibernateJpaDialect
private static final boolean
private final PersistenceProvider

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private Map<String, Object>
buildJpaPropertyMap(boolean connectionReleaseOnClose)

protected Class<?>

Returns:

the Hibernate database dialect class, or null if none found
determineDatabaseDialectClass
(Database
the target database
database
)

Determine the Hibernate database dialect class for the given target database.

public Class<? extends EntityManagerFactory>
getEntityManagerFactoryInterface()

Overrides org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter.getEntityManagerFactoryInterface.

Overrides default org.springframework.orm.jpa.JpaVendorAdapter.getEntityManagerFactoryInterface.

Return the vendor-specific EntityManagerFactory interface that the EntityManagerFactory proxy is supposed to implement.
public Class<? extends EntityManager>
getEntityManagerInterface()

Overrides org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter.getEntityManagerInterface.

Overrides default org.springframework.orm.jpa.JpaVendorAdapter.getEntityManagerInterface.

Return the vendor-specific EntityManager interface that this provider's EntityManagers will implement.
public HibernateJpaDialect
getJpaDialect()

Overrides org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter.getJpaDialect.

Overrides default org.springframework.orm.jpa.JpaVendorAdapter.getJpaDialect.

Return the vendor-specific JpaDialect implementation for this provider, or null if there is none.
public Map<String, Object>
getJpaPropertyMap(PersistenceUnitInfo
the PersistenceUnitInfo for the current persistence unit
pui
)

Overrides org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter.getJpaPropertyMap.

Overrides default org.springframework.orm.jpa.JpaVendorAdapter.getJpaPropertyMap.

Return a Map of vendor-specific JPA properties for the given persistence unit, typically based on settings in this JpaVendorAdapter instance.
public Map<String, Object>
getJpaPropertyMap()

Overrides org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter.getJpaPropertyMap.

Overrides default org.springframework.orm.jpa.JpaVendorAdapter.getJpaPropertyMap.

Return a Map of vendor-specific JPA properties, typically based on settings in this JpaVendorAdapter instance.
public PersistenceProvider
getPersistenceProvider()

Implements org.springframework.orm.jpa.JpaVendorAdapter.getPersistenceProvider.

Return the vendor-specific persistence provider.
public String
public void
setPrepareConnection(boolean prepareConnection)

Set whether to prepare the underlying JDBC Connection of a transactional Hibernate Session, that is, whether to apply a transaction-specific isolation level and/or the transaction's read-only flag to the underlying JDBC Connection.

Inherited from org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter:
getDatabasegetDatabasePlatformisGenerateDdlisShowSqlpostProcessEntityManagerpostProcessEntityManagerFactorysetDatabasesetDatabasePlatformsetGenerateDdlsetShowSql

Field Detail

entityManagerFactoryInterfaceback to summary
private final Class<? extends EntityManagerFactory> entityManagerFactoryInterface
entityManagerInterfaceback to summary
private final Class<? extends EntityManager> entityManagerInterface
jpaDialectback to summary
private final HibernateJpaDialect jpaDialect
oldDialectsPresentback to summary
private static final boolean oldDialectsPresent
persistenceProviderback to summary
private final PersistenceProvider persistenceProvider

Constructor Detail

HibernateJpaVendorAdapterback to summary
public HibernateJpaVendorAdapter()

Method Detail

buildJpaPropertyMapback to summary
private Map<String, Object> buildJpaPropertyMap(boolean connectionReleaseOnClose)
determineDatabaseDialectClassback to summary
protected Class<?> determineDatabaseDialectClass(Database database)

Determine the Hibernate database dialect class for the given target database.

Parameters
database:Database

the target database

Returns:Class<?>

the Hibernate database dialect class, or null if none found

Annotations
@SuppressWarnings:deprecation
@Nullable
getEntityManagerFactoryInterfaceback to summary
public Class<? extends EntityManagerFactory> getEntityManagerFactoryInterface()

Overrides org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter.getEntityManagerFactoryInterface.

Overrides default org.springframework.orm.jpa.JpaVendorAdapter.getEntityManagerFactoryInterface.

Doc from org.springframework.orm.jpa.JpaVendorAdapter.getEntityManagerFactoryInterface.

Return the vendor-specific EntityManagerFactory interface that the EntityManagerFactory proxy is supposed to implement.

If the provider does not offer any EntityManagerFactory extensions, the adapter should simply return the standard jakarta.persistence.EntityManagerFactory class here.

Annotations
@Override
getEntityManagerInterfaceback to summary
public Class<? extends EntityManager> getEntityManagerInterface()

Overrides org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter.getEntityManagerInterface.

Overrides default org.springframework.orm.jpa.JpaVendorAdapter.getEntityManagerInterface.

Doc from org.springframework.orm.jpa.JpaVendorAdapter.getEntityManagerInterface.

Return the vendor-specific EntityManager interface that this provider's EntityManagers will implement.

If the provider does not offer any EntityManager extensions, the adapter should simply return the standard jakarta.persistence.EntityManager class here.

Annotations
@Override
getJpaDialectback to summary
public HibernateJpaDialect getJpaDialect()

Overrides org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter.getJpaDialect.

Overrides default org.springframework.orm.jpa.JpaVendorAdapter.getJpaDialect.

Doc from org.springframework.orm.jpa.JpaVendorAdapter.getJpaDialect.

Return the vendor-specific JpaDialect implementation for this provider, or null if there is none.

Annotations
@Override
getJpaPropertyMapback to summary
public Map<String, Object> getJpaPropertyMap(PersistenceUnitInfo pui)

Overrides org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter.getJpaPropertyMap.

Overrides default org.springframework.orm.jpa.JpaVendorAdapter.getJpaPropertyMap.

Doc from org.springframework.orm.jpa.JpaVendorAdapter.getJpaPropertyMap.

Return a Map of vendor-specific JPA properties for the given persistence unit, typically based on settings in this JpaVendorAdapter instance.

Note that there might be further JPA properties defined on the EntityManagerFactory bean, which might potentially override individual JPA property values specified here.

This implementation delegates to getJpaPropertyMap() for non-unit-dependent properties. Effectively, this PersistenceUnitInfo-based variant only needs to be implemented if there is an actual need to react to unit-specific characteristics such as the transaction type.

Note

This variant will only be invoked in case of Jakarta EE style container bootstrapping where a PersistenceUnitInfo is present (i.e. LocalContainerEntityManagerFactoryBean). In case of simple Java SE style bootstrapping via jakarta.persistence.Persistence (i.e. LocalEntityManagerFactoryBean), the parameter-less getJpaPropertyMap() variant will be called directly.

Parameters
pui:PersistenceUnitInfo

the PersistenceUnitInfo for the current persistence unit

Returns:Map<String, Object>

a Map of JPA properties, as accepted by the standard JPA bootstrap facilities, or an empty Map if there are no properties to expose

Annotations
@Override
getJpaPropertyMapback to summary
public Map<String, Object> getJpaPropertyMap()

Overrides org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter.getJpaPropertyMap.

Overrides default org.springframework.orm.jpa.JpaVendorAdapter.getJpaPropertyMap.

Doc from org.springframework.orm.jpa.JpaVendorAdapter.getJpaPropertyMap.

Return a Map of vendor-specific JPA properties, typically based on settings in this JpaVendorAdapter instance.

Note that there might be further JPA properties defined on the EntityManagerFactory bean, which might potentially override individual JPA property values specified here.

Returns:Map<String, Object>

a Map of JPA properties, as accepted by the standard JPA bootstrap facilities, or an empty Map if there are no properties to expose

Annotations
@Override
getPersistenceProviderback to summary
public PersistenceProvider getPersistenceProvider()

Implements org.springframework.orm.jpa.JpaVendorAdapter.getPersistenceProvider.

Doc from org.springframework.orm.jpa.JpaVendorAdapter.getPersistenceProvider.

Return the vendor-specific persistence provider.

Annotations
@Override
getPersistenceProviderRootPackageback to summary
public String getPersistenceProviderRootPackage()

Overrides org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter.getPersistenceProviderRootPackage.

Overrides default org.springframework.orm.jpa.JpaVendorAdapter.getPersistenceProviderRootPackage.

Doc from org.springframework.orm.jpa.JpaVendorAdapter.getPersistenceProviderRootPackage.

Return the name of the persistence provider's root package (e.g. "oracle.toplink.essentials"). Will be used for excluding provider classes from temporary class overriding.

Annotations
@Override
setPrepareConnectionback to summary
public void setPrepareConnection(boolean prepareConnection)

Set whether to prepare the underlying JDBC Connection of a transactional Hibernate Session, that is, whether to apply a transaction-specific isolation level and/or the transaction's read-only flag to the underlying JDBC Connection.

See HibernateJpaDialect#setPrepareConnection(boolean) for details. This is just a convenience flag passed through to HibernateJpaDialect.

On Hibernate 5.1+, this flag remains true by default like against previous Hibernate versions. The vendor adapter manually enforces Hibernate's new connection handling mode DELAYED_ACQUISITION_AND_HOLD in that case unless a user-specified connection handling mode property indicates otherwise; switch this flag to false to avoid that interference.

NOTE: For a persistence unit with transaction type JTA e.g. on WebLogic, the connection release mode will never be altered from its provider default, i.e. not be forced to DELAYED_ACQUISITION_AND_HOLD by this flag. Alternatively, set Hibernate's "hibernate.connection.handling_mode" property to "DELAYED_ACQUISITION_AND_RELEASE_AFTER_TRANSACTION" or even "DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT" in such a scenario.

Since
4.3.1
See Also
PersistenceUnitInfo#getTransactionType(), getJpaPropertyMap(PersistenceUnitInfo), HibernateJpaDialect#beginTransaction