use of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in project cas by apereo.
the class JpaBeans method newEntityManagerFactoryBean.
/**
* New entity manager factory bean.
*
* @param config the config
* @return the local container entity manager factory bean
*/
public static LocalContainerEntityManagerFactoryBean newEntityManagerFactoryBean(final JpaConfigurationContext config) {
val bean = new LocalContainerEntityManagerFactoryBean();
bean.setJpaVendorAdapter(config.getJpaVendorAdapter());
if (config.getPersistenceProvider() != null) {
bean.setPersistenceProvider(config.getPersistenceProvider());
}
if (StringUtils.isNotBlank(config.getPersistenceUnitName())) {
bean.setPersistenceUnitName(config.getPersistenceUnitName());
}
if (!config.getPackagesToScan().isEmpty()) {
bean.setPackagesToScan(config.getPackagesToScan().toArray(ArrayUtils.EMPTY_STRING_ARRAY));
}
if (config.getDataSource() != null) {
bean.setDataSource(config.getDataSource());
}
bean.getJpaPropertyMap().putAll(config.getJpaProperties());
return bean;
}
use of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in project java-design-patterns by iluwatar.
the class AppConfig method entityManagerFactory.
/**
* Factory to create a especific instance of Entity Manager.
*/
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
var entityManager = new LocalContainerEntityManagerFactoryBean();
entityManager.setDataSource(dataSource());
entityManager.setPackagesToScan("com.iluwatar");
entityManager.setPersistenceProvider(new HibernatePersistenceProvider());
entityManager.setJpaProperties(jpaProperties());
return entityManager;
}
use of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in project av-service by dvoraka.
the class DbCommonConfig method entityManagerFactory.
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, Properties hibernateProperties) {
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(dataSource);
entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
entityManagerFactoryBean.setPackagesToScan("dvoraka.avservice.db.model");
entityManagerFactoryBean.setJpaProperties(hibernateProperties);
return entityManagerFactoryBean;
}
use of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in project spring-boot by spring-projects.
the class AbstractJpaAutoConfigurationTests method customPersistenceUnitPostProcessors.
@Test
void customPersistenceUnitPostProcessors() {
this.contextRunner.withUserConfiguration(TestConfigurationWithCustomPersistenceUnitPostProcessors.class).run((context) -> {
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = context.getBean(LocalContainerEntityManagerFactoryBean.class);
PersistenceUnitInfo persistenceUnitInfo = entityManagerFactoryBean.getPersistenceUnitInfo();
assertThat(persistenceUnitInfo).isNotNull();
assertThat(persistenceUnitInfo.getManagedClassNames()).contains("customized.attribute.converter.class.name");
});
}
use of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in project spring-boot by spring-projects.
the class AbstractJpaAutoConfigurationTests method customJpaProperties.
@Test
void customJpaProperties() {
this.contextRunner.withPropertyValues("spring.jpa.properties.a:b", "spring.jpa.properties.a.b:c", "spring.jpa.properties.c:d").run((context) -> {
LocalContainerEntityManagerFactoryBean bean = context.getBean(LocalContainerEntityManagerFactoryBean.class);
Map<String, Object> map = bean.getJpaPropertyMap();
assertThat(map.get("a")).isEqualTo("b");
assertThat(map.get("c")).isEqualTo("d");
assertThat(map.get("a.b")).isEqualTo("c");
});
}
Aggregations