类 EntityManagerFactoryAccessor
- java.lang.Object
- org.springframework.orm.jpa.EntityManagerFactoryAccessor
- 所有已实现的接口:
Aware
,BeanFactoryAware
public abstract class EntityManagerFactoryAccessor extends Object implements BeanFactoryAware
Base class for any class that needs to access a JPAEntityManagerFactory
, usually in order to obtain a JPAEntityManager
. Defines common properties.- 从以下版本开始:
- 2.0
- 作者:
- Juergen Hoeller
- 另请参阅:
EntityManagerFactoryUtils
构造器概要
构造器 构造器 说明 EntityManagerFactoryAccessor()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected EntityManager
createEntityManager()
Obtain a new EntityManager from this accessor's EntityManagerFactory.EntityManagerFactory
getEntityManagerFactory()
Return the JPA EntityManagerFactory that should be used to create EntityManagers.Map<String,Object>
getJpaPropertyMap()
Allow Map access to the JPA properties to be passed to the persistence provider, with the option to add or override specific entries.String
getPersistenceUnitName()
Return the name of the persistence unit to access the EntityManagerFactory for, if any.protected EntityManager
getTransactionalEntityManager()
Obtain the transactional EntityManager for this accessor's EntityManagerFactory, if any.void
setBeanFactory(BeanFactory beanFactory)
Retrieves an EntityManagerFactory by persistence unit name, if none set explicitly.void
setEntityManagerFactory(EntityManagerFactory emf)
Set the JPA EntityManagerFactory that should be used to create EntityManagers.void
setJpaProperties(Properties jpaProperties)
Specify JPA properties, to be passed intoEntityManagerFactory.createEntityManager(Map)
(if any).void
setJpaPropertyMap(Map<String,Object> jpaProperties)
Specify JPA properties as a Map, to be passed intoEntityManagerFactory.createEntityManager(Map)
(if any).void
setPersistenceUnitName(String persistenceUnitName)
Set the name of the persistence unit to access the EntityManagerFactory for.
构造器详细资料
EntityManagerFactoryAccessor
public EntityManagerFactoryAccessor()
方法详细资料
setEntityManagerFactory
public void setEntityManagerFactory(EntityManagerFactory emf)
Set the JPA EntityManagerFactory that should be used to create EntityManagers.
getEntityManagerFactory
public EntityManagerFactory getEntityManagerFactory()
Return the JPA EntityManagerFactory that should be used to create EntityManagers.
setPersistenceUnitName
public void setPersistenceUnitName(String persistenceUnitName)
Set the name of the persistence unit to access the EntityManagerFactory for.This is an alternative to specifying the EntityManagerFactory by direct reference, resolving it by its persistence unit name instead. If no EntityManagerFactory and no persistence unit name have been specified, a default EntityManagerFactory will be retrieved through finding a single unique bean of type EntityManagerFactory.
getPersistenceUnitName
public String getPersistenceUnitName()
Return the name of the persistence unit to access the EntityManagerFactory for, if any.
setJpaProperties
public void setJpaProperties(Properties jpaProperties)
Specify JPA properties, to be passed intoEntityManagerFactory.createEntityManager(Map)
(if any).Can be populated with a String "value" (parsed via PropertiesEditor) or a "props" element in XML bean definitions.
setJpaPropertyMap
public void setJpaPropertyMap(Map<String,Object> jpaProperties)
Specify JPA properties as a Map, to be passed intoEntityManagerFactory.createEntityManager(Map)
(if any).Can be populated with a "map" or "props" element in XML bean definitions.
getJpaPropertyMap
public Map<String,Object> getJpaPropertyMap()
Allow Map access to the JPA properties to be passed to the persistence provider, with the option to add or override specific entries.Useful for specifying entries directly, for example via "jpaPropertyMap[myKey]".
setBeanFactory
public void setBeanFactory(BeanFactory beanFactory) throws BeansException
Retrieves an EntityManagerFactory by persistence unit name, if none set explicitly. Falls back to a default EntityManagerFactory bean if no persistence unit specified.- 指定者:
setBeanFactory
在接口中BeanFactoryAware
- 参数:
beanFactory
- owning BeanFactory (nevernull
). The bean can immediately call methods on the factory.- 抛出:
BeansException
- in case of initialization errors- 另请参阅:
setPersistenceUnitName(java.lang.String)
createEntityManager
protected EntityManager createEntityManager() throws IllegalStateException
Obtain a new EntityManager from this accessor's EntityManagerFactory.Can be overridden in subclasses to create specific EntityManager variants.
- 返回:
- a new EntityManager
- 抛出:
IllegalStateException
- if this accessor is not configured with an EntityManagerFactory- 另请参阅:
EntityManagerFactory.createEntityManager()
,EntityManagerFactory.createEntityManager(java.util.Map)
getTransactionalEntityManager
protected EntityManager getTransactionalEntityManager() throws IllegalStateException
Obtain the transactional EntityManager for this accessor's EntityManagerFactory, if any.- 返回:
- the transactional EntityManager, or
null
if none - 抛出:
IllegalStateException
- if this accessor is not configured with an EntityManagerFactory- 另请参阅:
EntityManagerFactoryUtils.getTransactionalEntityManager(javax.persistence.EntityManagerFactory)
,EntityManagerFactoryUtils.getTransactionalEntityManager(javax.persistence.EntityManagerFactory, java.util.Map)