Class EntityManagerFactoryAccessor
java.lang.Object
org.springframework.orm.jpa.EntityManagerFactoryAccessor
- All Implemented Interfaces:
- Aware, BeanFactoryAware
- Direct Known Subclasses:
- OpenEntityManagerInViewInterceptor, SharedEntityManagerBean
Base class for any class that needs to access a JPA 
EntityManagerFactory,
usually in order to obtain a JPA EntityManager. Defines common properties.- Since:
- 2.0
- Author:
- Juergen Hoeller
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected final org.apache.commons.logging.LogLogger available to subclasses.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected jakarta.persistence.EntityManagerObtain a new EntityManager from this accessor's EntityManagerFactory.@Nullable jakarta.persistence.EntityManagerFactoryReturn the JPA EntityManagerFactory that should be used to create EntityManagers.AllowMapaccess to the JPA properties to be passed to the persistence provider, with the option to add or override specific entries.Return the name of the persistence unit to access the EntityManagerFactory for, if any.protected @Nullable jakarta.persistence.EntityManagerObtain the transactional EntityManager for this accessor's EntityManagerFactory, if any.protected final jakarta.persistence.EntityManagerFactoryObtain the EntityManagerFactory for actual use.voidsetBeanFactory(BeanFactory beanFactory) Retrieves an EntityManagerFactory by persistence unit name, if none set explicitly.voidsetEntityManagerFactory(@Nullable jakarta.persistence.EntityManagerFactory emf) Set the JPA EntityManagerFactory that should be used to create EntityManagers.voidsetJpaProperties(Properties jpaProperties) Specify JPA properties, to be passed intoEntityManagerFactory.createEntityManager(Map)(if any).voidsetJpaPropertyMap(@Nullable Map<String, Object> jpaProperties) Specify JPA properties as a Map, to be passed intoEntityManagerFactory.createEntityManager(Map)(if any).voidsetPersistenceUnitName(@Nullable String persistenceUnitName) Set the name of the persistence unit to access the EntityManagerFactory for.
- 
Field Details- 
loggerprotected final org.apache.commons.logging.Log loggerLogger available to subclasses.
 
- 
- 
Constructor Details- 
EntityManagerFactoryAccessorpublic EntityManagerFactoryAccessor()
 
- 
- 
Method Details- 
setEntityManagerFactorySet the JPA EntityManagerFactory that should be used to create EntityManagers.- See Also:
 
- 
getEntityManagerFactoryReturn the JPA EntityManagerFactory that should be used to create EntityManagers.
- 
obtainEntityManagerFactoryprotected final jakarta.persistence.EntityManagerFactory obtainEntityManagerFactory()Obtain the EntityManagerFactory for actual use.- Returns:
- the EntityManagerFactory (never null)
- Throws:
- IllegalStateException- in case of no EntityManagerFactory set
- Since:
- 5.0
 
- 
setPersistenceUnitNameSet 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. - See Also:
 
- 
getPersistenceUnitName
- 
setJpaPropertiesSpecify 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. - See Also:
 
- 
setJpaPropertyMap
- 
getJpaPropertyMap
- 
setBeanFactoryRetrieves an EntityManagerFactory by persistence unit name, if none set explicitly. Falls back to a default EntityManagerFactory bean if no persistence unit specified.- Specified by:
- setBeanFactoryin interface- BeanFactoryAware
- Parameters:
- beanFactory- owning BeanFactory (never- null). The bean can immediately call methods on the factory.
- Throws:
- BeansException- in case of initialization errors
- See Also:
 
- 
createEntityManagerObtain a new EntityManager from this accessor's EntityManagerFactory.Can be overridden in subclasses to create specific EntityManager variants. - Returns:
- a new EntityManager
- Throws:
- IllegalStateException- if this accessor is not configured with an EntityManagerFactory
- See Also:
 
- 
getTransactionalEntityManagerprotected @Nullable jakarta.persistence.EntityManager getTransactionalEntityManager() throws IllegalStateExceptionObtain the transactional EntityManager for this accessor's EntityManagerFactory, if any.- Returns:
- the transactional EntityManager, or nullif none
- Throws:
- IllegalStateException- if this accessor is not configured with an EntityManagerFactory
- See Also:
 
 
-