Search in sources :

Example 1 with PersistenceUnitManager

use of org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager in project spring-boot by spring-projects.

the class AbstractJpaAutoConfigurationTests method customPersistenceUnitManager.

@Test
public void customPersistenceUnitManager() throws Exception {
    setupTestConfiguration(TestConfigurationWithCustomPersistenceUnitManager.class);
    this.context.refresh();
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = this.context.getBean(LocalContainerEntityManagerFactoryBean.class);
    Field field = LocalContainerEntityManagerFactoryBean.class.getDeclaredField("persistenceUnitManager");
    field.setAccessible(true);
    assertThat(field.get(entityManagerFactoryBean)).isEqualTo(this.context.getBean(PersistenceUnitManager.class));
}
Also used : Field(java.lang.reflect.Field) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) DefaultPersistenceUnitManager(org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager) PersistenceUnitManager(org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager) Test(org.junit.Test)

Example 2 with PersistenceUnitManager

use of org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager in project spring-framework by spring-projects.

the class LocalContainerEntityManagerFactoryBean method createNativeEntityManagerFactory.

@Override
protected EntityManagerFactory createNativeEntityManagerFactory() throws PersistenceException {
    PersistenceUnitManager managerToUse = this.persistenceUnitManager;
    if (this.persistenceUnitManager == null) {
        this.internalPersistenceUnitManager.afterPropertiesSet();
        managerToUse = this.internalPersistenceUnitManager;
    }
    this.persistenceUnitInfo = determinePersistenceUnitInfo(managerToUse);
    JpaVendorAdapter jpaVendorAdapter = getJpaVendorAdapter();
    if (jpaVendorAdapter != null && this.persistenceUnitInfo instanceof SmartPersistenceUnitInfo) {
        ((SmartPersistenceUnitInfo) this.persistenceUnitInfo).setPersistenceProviderPackageName(jpaVendorAdapter.getPersistenceProviderRootPackage());
    }
    PersistenceProvider provider = getPersistenceProvider();
    if (provider == null) {
        String providerClassName = this.persistenceUnitInfo.getPersistenceProviderClassName();
        if (providerClassName == null) {
            throw new IllegalArgumentException("No PersistenceProvider specified in EntityManagerFactory configuration, " + "and chosen PersistenceUnitInfo does not specify a provider class name either");
        }
        Class<?> providerClass = ClassUtils.resolveClassName(providerClassName, getBeanClassLoader());
        provider = (PersistenceProvider) BeanUtils.instantiateClass(providerClass);
    }
    if (logger.isInfoEnabled()) {
        logger.info("Building JPA container EntityManagerFactory for persistence unit '" + this.persistenceUnitInfo.getPersistenceUnitName() + "'");
    }
    EntityManagerFactory emf = provider.createContainerEntityManagerFactory(this.persistenceUnitInfo, getJpaPropertyMap());
    postProcessEntityManagerFactory(emf, this.persistenceUnitInfo);
    return emf;
}
Also used : SmartPersistenceUnitInfo(org.springframework.orm.jpa.persistenceunit.SmartPersistenceUnitInfo) PersistenceProvider(javax.persistence.spi.PersistenceProvider) EntityManagerFactory(javax.persistence.EntityManagerFactory) PersistenceUnitManager(org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager) DefaultPersistenceUnitManager(org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager)

Aggregations

DefaultPersistenceUnitManager (org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager)2 PersistenceUnitManager (org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager)2 Field (java.lang.reflect.Field)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 PersistenceProvider (javax.persistence.spi.PersistenceProvider)1 Test (org.junit.Test)1 LocalContainerEntityManagerFactoryBean (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)1 SmartPersistenceUnitInfo (org.springframework.orm.jpa.persistenceunit.SmartPersistenceUnitInfo)1