@Before public void setUp() throws Exception { factory = mock(EntityManagerFactory.class); manager = mock(EntityManager.class); tx = mock(EntityTransaction.class); JpaTransactionManager tm = new JpaTransactionManager(factory); tt = new TransactionTemplate(tm); given(factory.createEntityManager()).willReturn(manager); given(manager.getTransaction()).willReturn(tx); given(manager.isOpen()).willReturn(true); bean = new EntityManagerHoldingBean(); @SuppressWarnings("serial") PersistenceAnnotationBeanPostProcessor pabpp = new PersistenceAnnotationBeanPostProcessor() { @Override protected EntityManagerFactory findEntityManagerFactory(String unitName, String requestingBeanName) { return factory; } }; pabpp.postProcessPropertyValues(null, null, bean, "bean"); assertTrue(TransactionSynchronizationManager.getResourceMap().isEmpty()); assertFalse(TransactionSynchronizationManager.isSynchronizationActive()); }
/** * Bean that helps Spring to understand JPA annotations * @return Bean */ @Bean public PersistenceAnnotationBeanPostProcessor paPostProcessor(){ return new PersistenceAnnotationBeanPostProcessor(); }
@Bean public static PersistenceAnnotationBeanPostProcessor persistenceAnnotationBeanPostProcessor() { return new PersistenceAnnotationBeanPostProcessor(); }
@Bean public PersistenceAnnotationBeanPostProcessor persistenceAnnotation() { return new PersistenceAnnotationBeanPostProcessor(); }
/** * It’s important to understand that @PersistenceUnit and @PersistenceContext aren’t Spring annotations;<br> * they’re provided by the JPA specification. In order for Spring to understand them and inject an EntityManagerFactory or EntityManager,<br> * Spring’s PersistenceAnnotationBeanPostProcessor must be configured. <br> * If you’re already using <context:annotation-config> or <context:component-scan>,<br> * then you’re good to go because those configuration elements automatically register a PersistenceAnnotationBeanPostProcessor bean. * * @return PersistenceAnnotationBeanPostProcessor */ @Bean public PersistenceAnnotationBeanPostProcessor paPostProcessor() { return new PersistenceAnnotationBeanPostProcessor(); }