public abstract class EntityManagerFactoryAccessor extends java.lang.Object implements BeanFactoryAware
EntityManagerFactory
,
usually in order to obtain a JPA EntityManager
. Defines common properties.EntityManagerFactoryUtils
Modifier and Type | Field and Description |
---|---|
protected Log |
logger
Logger available to subclasses
|
Constructor and Description |
---|
EntityManagerFactoryAccessor() |
Modifier and Type | Method and Description |
---|---|
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.
|
java.util.Map<java.lang.String,java.lang.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.
|
java.lang.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.
|
protected EntityManagerFactory |
obtainEntityManagerFactory()
Obtain the EntityManagerFactory for actual use.
|
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(java.util.Properties jpaProperties)
Specify JPA properties, to be passed into
EntityManagerFactory.createEntityManager(Map) (if any). |
void |
setJpaPropertyMap(java.util.Map<java.lang.String,java.lang.Object> jpaProperties)
Specify JPA properties as a Map, to be passed into
EntityManagerFactory.createEntityManager(Map) (if any). |
void |
setPersistenceUnitName(java.lang.String persistenceUnitName)
Set the name of the persistence unit to access the EntityManagerFactory for.
|
protected final Log logger
public void setEntityManagerFactory(@Nullable EntityManagerFactory emf)
@Nullable public EntityManagerFactory getEntityManagerFactory()
protected final EntityManagerFactory obtainEntityManagerFactory()
null
)java.lang.IllegalStateException
- in case of no EntityManagerFactory setpublic void setPersistenceUnitName(@Nullable java.lang.String persistenceUnitName)
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.
@Nullable public java.lang.String getPersistenceUnitName()
public void setJpaProperties(java.util.Properties jpaProperties)
EntityManagerFactory.createEntityManager(Map)
(if any).
Can be populated with a String "value" (parsed via PropertiesEditor) or a "props" element in XML bean definitions.
public void setJpaPropertyMap(@Nullable java.util.Map<java.lang.String,java.lang.Object> jpaProperties)
EntityManagerFactory.createEntityManager(Map)
(if any).
Can be populated with a "map" or "props" element in XML bean definitions.
public java.util.Map<java.lang.String,java.lang.Object> getJpaPropertyMap()
Useful for specifying entries directly, for example via "jpaPropertyMap[myKey]".
public void setBeanFactory(BeanFactory beanFactory) throws BeansException
setBeanFactory
in interface BeanFactoryAware
beanFactory
- owning BeanFactory (never null
).
The bean can immediately call methods on the factory.BeansException
- in case of initialization errorssetPersistenceUnitName(java.lang.String)
protected EntityManager createEntityManager() throws java.lang.IllegalStateException
Can be overridden in subclasses to create specific EntityManager variants.
java.lang.IllegalStateException
- if this accessor is not configured with an EntityManagerFactoryEntityManagerFactory.createEntityManager()
,
EntityManagerFactory.createEntityManager(java.util.Map)
@Nullable protected EntityManager getTransactionalEntityManager() throws java.lang.IllegalStateException
null
if nonejava.lang.IllegalStateException
- if this accessor is not configured with an EntityManagerFactoryEntityManagerFactoryUtils.getTransactionalEntityManager(javax.persistence.EntityManagerFactory)
,
EntityManagerFactoryUtils.getTransactionalEntityManager(javax.persistence.EntityManagerFactory, java.util.Map)