The Spring Framework

org.springframework.orm.jpa.support
Class PersistenceAnnotationBeanPostProcessor

java.lang.Object
  extended by org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter
      extended by org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor
All Implemented Interfaces:
BeanFactoryAware, BeanPostProcessor, InstantiationAwareBeanPostProcessor

public class PersistenceAnnotationBeanPostProcessor
extends InstantiationAwareBeanPostProcessorAdapter
implements BeanFactoryAware

BeanPostProcessor that processes PersistenceUnit and PersistenceContext annotations, for injection of the corresponding JPA resources EntityManagerFactory and EntityManager. Any such annotated fields or methods in any Spring-managed object will automatically be injected.

This post-processor will inject sub-interfaces of EntityManagerFactory and EntityManager if the annotated fields or methods are declared as such. The actual type will be verified early, with the exception of a shared ("transactional") EntityManager reference, where type mismatches might be detected as late as on the first actual invocation.

Since:
2.0
Author:
Rod Johnson, Juergen Hoeller
See Also:
PersistenceUnit, PersistenceContext

Field Summary
protected  Log logger
           
 
Constructor Summary
PersistenceAnnotationBeanPostProcessor()
           
 
Method Summary
protected  javax.persistence.EntityManagerFactory findDefaultEntityManagerFactory()
           
protected  javax.persistence.EntityManagerFactory findEntityManagerFactory(String emfName)
          Find an EntityManagerFactory with the given name in the current application context.
protected  javax.persistence.EntityManagerFactory findNamedEntityManagerFactory(String emfName)
           
 boolean postProcessAfterInstantiation(Object bean, String beanName)
          Perform operations after the bean has been instantiated, via a constructor or factory method, but before Spring property population (from explicit properties or autowiring) occurs.
 void setBeanFactory(BeanFactory beanFactory)
          Callback that supplies the owning factory to a bean instance.
 
Methods inherited from class org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter
postProcessAfterInitialization, postProcessBeforeInitialization, postProcessBeforeInstantiation, postProcessPropertyValues
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final Log logger
Constructor Detail

PersistenceAnnotationBeanPostProcessor

public PersistenceAnnotationBeanPostProcessor()
Method Detail

setBeanFactory

public void setBeanFactory(BeanFactory beanFactory)
Description copied from interface: BeanFactoryAware
Callback that supplies the owning factory to a bean instance.

Invoked after the population of normal bean properties but before an initialization callback such as InitializingBean.afterPropertiesSet() or a custom init-method.

Specified by:
setBeanFactory in interface BeanFactoryAware
Parameters:
beanFactory - owning BeanFactory (may not be null). The bean can immediately call methods on the factory.
See Also:
BeanInitializationException

postProcessAfterInstantiation

public boolean postProcessAfterInstantiation(Object bean,
                                             String beanName)
                                      throws BeansException
Description copied from interface: InstantiationAwareBeanPostProcessor
Perform operations after the bean has been instantiated, via a constructor or factory method, but before Spring property population (from explicit properties or autowiring) occurs.

Specified by:
postProcessAfterInstantiation in interface InstantiationAwareBeanPostProcessor
Overrides:
postProcessAfterInstantiation in class InstantiationAwareBeanPostProcessorAdapter
Parameters:
bean - the bean instance created, but whose properties have not yet been set
beanName - the name of the bean
Returns:
true if properties should be set on the bean; false if property population should be skipped. Normal implementations should return true. Returning false will also prevent any subsequent InstantiationAwareBeanPostProcessor instances being invoked on this bean instance.
Throws:
BeansException - in case of errors

findEntityManagerFactory

protected javax.persistence.EntityManagerFactory findEntityManagerFactory(String emfName)
                                                                   throws IllegalStateException
Find an EntityManagerFactory with the given name in the current application context.

Parameters:
emfName - the name of the EntityManagerFactory
Returns:
the EntityManagerFactory
Throws:
IllegalStateException - if there is no such EntityManagerFactory in the context

findNamedEntityManagerFactory

protected javax.persistence.EntityManagerFactory findNamedEntityManagerFactory(String emfName)

findDefaultEntityManagerFactory

protected javax.persistence.EntityManagerFactory findDefaultEntityManagerFactory()

The Spring Framework

Copyright © 2002-2006 The Spring Framework.