Package org.springframework.orm.jpa.vendor

# Class HibernateJpaVendorAdapter

java.lang.Object
org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter
org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter

All Implemented Interfaces:
  `JpaVendorAdapter`

public class HibernateJpaVendorAdapter extends AbstractJpaVendorAdapter
`JpaVendorAdapter` implementation for Hibernate. Compatible with Hibernate ORM 5.5/5.6 as well as 6.x.

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 `SmartPersistenceUnitInfo.getManagedPackages()`), for example, containing Hibernate `FilterDef` annotations, along with Spring-driven entity scanning which requires no `persistence.xml` (`LocalContainerEntityManagerFactoryBean.setPackagesToScan(java.lang.String...)`).

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 `AbstractJpaVendorAdapter.setDatabase(org.springframework.orm.jpa.vendor.Database)` 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(boolean)`, at least for non-JTA scenarios; you may override this through corresponding native Hibernate properties.

Since:
  2.0
Author:
  Juergen Hoeller, Rod Johnson
See Also:
  - `HibernateJpaDialect`

## Constructor Summary

Constructors
Constructor
Description
`HibernateJpaVendorAdapter()`

## Method Summary

Modifier and Type
Method
Description
`protected Class<?>`
`determineDatabaseDialectClass(Database database)`
Determine the Hibernate database dialect class for the given target database.
`Class<? extends EntityManagerFactory>`
`getEntityManagerFactoryInterface()`
Return the vendor-specific EntityManagerFactory interface that the EntityManagerFactory proxy is supposed to implement.
`Class<? extends EntityManager>`
`getEntityManagerInterface()`
Return the vendor-specific EntityManager interface that this provider's EntityManagers will implement.
`HibernateJpaDialect`
`getJpaDialect()`
Return the vendor-specific JpaDialect implementation for this provider, or `null` if there is none.
`Map<String,Object>`
`getJpaPropertyMap()`
Return a Map of vendor-specific JPA properties, typically based on settings in this JpaVendorAdapter instance.
`Map<String,Object>`
`getJpaPropertyMap(PersistenceUnitInfo pui)`
Return a Map of vendor-specific JPA properties for the given persistence unit, typically based on settings in this JpaVendorAdapter instance.
`PersistenceProvider`
`getPersistenceProvider()`
Return the vendor-specific persistence provider.
`String`
`getPersistenceProviderRootPackage()`
Return the name of the persistence provider's root package (for example, "oracle.toplink.essentials").
`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.

### Methods inherited from class org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter

`getDatabase, getDatabasePlatform, isGenerateDdl, isShowSql, postProcessEntityManager, postProcessEntityManagerFactory, setDatabase, setDatabasePlatform, setGenerateDdl, setShowSql`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### HibernateJpaVendorAdapter

public HibernateJpaVendorAdapter()

## Method Details

### setPrepareConnection

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, for example, 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(jakarta.persistence.EntityManager, org.springframework.transaction.TransactionDefinition)`

### getPersistenceProvider

public PersistenceProvider getPersistenceProvider()
Description copied from interface: `JpaVendorAdapter`
Return the vendor-specific persistence provider.

### getPersistenceProviderRootPackage

public String getPersistenceProviderRootPackage()
Description copied from interface: `JpaVendorAdapter`
Return the name of the persistence provider's root package (for example, "oracle.toplink.essentials"). Will be used for excluding provider classes from temporary class overriding.

Specified by:
  `getPersistenceProviderRootPackage` in interface `JpaVendorAdapter`
Overrides:
  `getPersistenceProviderRootPackage` in class `AbstractJpaVendorAdapter`

### getJpaPropertyMap

public Map<String,Object> getJpaPropertyMap(PersistenceUnitInfo pui)
Description copied from interface: `JpaVendorAdapter`
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 `JpaVendorAdapter.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 `Persistence` (i.e. `LocalEntityManagerFactoryBean`), the parameter-less `JpaVendorAdapter.getJpaPropertyMap()` variant will be called directly.

Specified by:
  `getJpaPropertyMap` in interface `JpaVendorAdapter`
Overrides:
  `getJpaPropertyMap` in class `AbstractJpaVendorAdapter`
Parameters:
  `pui` - the PersistenceUnitInfo for the current persistence unit
Returns:
  a Map of JPA properties, as accepted by the standard JPA bootstrap facilities, or an empty Map if there are no properties to expose
See Also:
  - `PersistenceUnitInfo.getTransactionType()`
  - `PersistenceProvider.createContainerEntityManagerFactory(PersistenceUnitInfo, Map)`

### getJpaPropertyMap

public Map<String,Object> getJpaPropertyMap()
Description copied from interface: `JpaVendorAdapter`
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.

Specified by:
  `getJpaPropertyMap` in interface `JpaVendorAdapter`
Overrides:
  `getJpaPropertyMap` in class `AbstractJpaVendorAdapter`
Returns:
  a Map of JPA properties, as accepted by the standard JPA bootstrap facilities, or an empty Map if there are no properties to expose
See Also:
  - `Persistence.createEntityManagerFactory(String, Map)`

### determineDatabaseDialectClass

@Nullable protected Class<?> determineDatabaseDialectClass(Database database)
Determine the Hibernate database dialect class for the given target database.

Parameters:
  `database` - the target database
Returns:
  the Hibernate database dialect class, or `null` if none found

### getJpaDialect

public HibernateJpaDialect getJpaDialect()
Description copied from interface: `JpaVendorAdapter`
Return the vendor-specific JpaDialect implementation for this provider, or `null` if there is none.

Specified by:
  `getJpaDialect` in interface `JpaVendorAdapter`
Overrides:
  `getJpaDialect` in class `AbstractJpaVendorAdapter`

### getEntityManagerFactoryInterface

public Class<? extends EntityManagerFactory> getEntityManagerFactoryInterface()
Description copied from interface: `JpaVendorAdapter`
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 `EntityManagerFactory` class here.

Specified by:
  `getEntityManagerFactoryInterface` in interface `JpaVendorAdapter`
Overrides:
  `getEntityManagerFactoryInterface` in class `AbstractJpaVendorAdapter`

### getEntityManagerInterface

public Class<? extends EntityManager> getEntityManagerInterface()
Description copied from interface: `JpaVendorAdapter`
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 `EntityManager` class here.

Specified by:
  `getEntityManagerInterface` in interface `JpaVendorAdapter`
Overrides:
  `getEntityManagerInterface` in class `AbstractJpaVendorAdapter`