类 HibernateJpaVendorAdapter
- java.lang.Object
- org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter
- org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter
- 所有已实现的接口:
JpaVendorAdapter
public class HibernateJpaVendorAdapter extends AbstractJpaVendorAdapter
JpaVendorAdapter
implementation for Hibernate EntityManager. Developed and tested against Hibernate 3.6, 4.2/4.3 as well as 5.x. Hibernate 4.2+ is strongly recommended for use with Spring 4.0+.Exposes Hibernate's persistence provider and EntityManager extension interface, and adapts
AbstractJpaVendorAdapter
's common configuration settings. Also supports the detection of annotated packages (throughSmartPersistenceUnitInfo.getManagedPackages()
), e.g. containing HibernateFilterDef
annotations, along with Spring-driven entity scanning which requires nopersistence.xml
(LocalContainerEntityManagerFactoryBean.setPackagesToScan(java.lang.String...)
).Note that the package location of Hibernate's JPA support changed from 4.2 to 4.3: from
org.hibernate.ejb.HibernateEntityManager(Factory)
toorg.hibernate.jpa.HibernateEntityManager(Factory)
. As of Spring 4.0, we're exposing the correct, non-deprecated variant depending on the Hibernate version encountered at runtime, in order to avoid deprecation log entries.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 eitherAbstractJpaVendorAdapter.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 prefersON_CLOSE
behavior, aligned withHibernateJpaDialect.setPrepareConnection(boolean)
, at least for non-JTA scenarios; you may override this through corresponding native Hibernate properties.- 从以下版本开始:
- 2.0
- 作者:
- Juergen Hoeller, Rod Johnson
- 另请参阅:
HibernateJpaDialect
,HibernatePersistence
,HibernateEntityManager
构造器概要
构造器 构造器 说明 HibernateJpaVendorAdapter()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 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, ornull
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 (e.g.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.从类继承的方法 org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter
getDatabase, getDatabasePlatform, isGenerateDdl, isShowSql, postProcessEntityManagerFactory, setDatabase, setDatabasePlatform, setGenerateDdl, setShowSql
构造器详细资料
HibernateJpaVendorAdapter
public HibernateJpaVendorAdapter()
方法详细资料
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 toHibernateJpaDialect
.On Hibernate 5.1/5.2, this flag remains
true
by default like against previous Hibernate versions. The vendor adapter manually enforces Hibernate's new connection handling modeDELAYED_ACQUISITION_AND_HOLD
in that case unless a user-specified connection handling mode property indicates otherwise; switch this flag tofalse
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 5.2'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.
getPersistenceProvider
public PersistenceProvider getPersistenceProvider()
从接口复制的说明:JpaVendorAdapter
Return the vendor-specific persistence provider.
getPersistenceProviderRootPackage
public String getPersistenceProviderRootPackage()
从接口复制的说明:JpaVendorAdapter
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.
getJpaPropertyMap
public Map<String,Object> getJpaPropertyMap(PersistenceUnitInfo pui)
从接口复制的说明: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 Java EE style container bootstrapping where a
PersistenceUnitInfo
is present (i.e.LocalContainerEntityManagerFactoryBean
. In case of simple Java SE style bootstrapping viaPersistence
(i.e.LocalEntityManagerFactoryBean
), the parameter-lessJpaVendorAdapter.getJpaPropertyMap()
variant will be called directly.- 指定者:
getJpaPropertyMap
在接口中JpaVendorAdapter
- 覆盖:
getJpaPropertyMap
在类中AbstractJpaVendorAdapter
- 参数:
pui
- the PersistenceUnitInfo for the current persistence unit- 返回:
- a Map of JPA properties, as accepted by the standard JPA bootstrap facilities, or an empty Map if there are no properties to expose
- 另请参阅:
PersistenceUnitInfo.getTransactionType()
,PersistenceProvider.createContainerEntityManagerFactory(PersistenceUnitInfo, Map)
getJpaPropertyMap
public Map<String,Object> getJpaPropertyMap()
从接口复制的说明: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.
- 指定者:
getJpaPropertyMap
在接口中JpaVendorAdapter
- 覆盖:
getJpaPropertyMap
在类中AbstractJpaVendorAdapter
- 返回:
- a Map of JPA properties, as accepted by the standard JPA bootstrap facilities, or an empty Map if there are no properties to expose
- 另请参阅:
Persistence.createEntityManagerFactory(String, Map)
determineDatabaseDialectClass
protected Class<?> determineDatabaseDialectClass(Database database)
Determine the Hibernate database dialect class for the given target database.- 参数:
database
- the target database- 返回:
- the Hibernate database dialect class, or
null
if none found
getJpaDialect
public HibernateJpaDialect getJpaDialect()
从接口复制的说明:JpaVendorAdapter
Return the vendor-specific JpaDialect implementation for this provider, ornull
if there is none.- 指定者:
getJpaDialect
在接口中JpaVendorAdapter
- 覆盖:
getJpaDialect
在类中AbstractJpaVendorAdapter
getEntityManagerFactoryInterface
public Class<? extends EntityManagerFactory> getEntityManagerFactoryInterface()
从接口复制的说明: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.
getEntityManagerInterface
public Class<? extends EntityManager> getEntityManagerInterface()
从接口复制的说明: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.