Search in sources :

Example 46 with LocalContainerEntityManagerFactoryBean

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;
}
Also used : lombok.val(lombok.val) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 47 with LocalContainerEntityManagerFactoryBean

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;
}
Also used : HibernatePersistenceProvider(org.hibernate.jpa.HibernatePersistenceProvider) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 48 with LocalContainerEntityManagerFactoryBean

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;
}
Also used : HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 49 with LocalContainerEntityManagerFactoryBean

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");
    });
}
Also used : PersistenceUnitInfo(jakarta.persistence.spi.PersistenceUnitInfo) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) Test(org.junit.jupiter.api.Test)

Example 50 with LocalContainerEntityManagerFactoryBean

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");
    });
}
Also used : LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) Test(org.junit.jupiter.api.Test)

Aggregations

LocalContainerEntityManagerFactoryBean (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)75 Bean (org.springframework.context.annotation.Bean)63 HibernateJpaVendorAdapter (org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter)42 Properties (java.util.Properties)14 JpaVendorAdapter (org.springframework.orm.jpa.JpaVendorAdapter)7 HashMap (java.util.HashMap)4 JpaConfigDataHolder (org.apereo.cas.configuration.model.support.jpa.JpaConfigDataHolder)4 Test (org.junit.jupiter.api.Test)4 DependsOn (org.springframework.context.annotation.DependsOn)4 Lazy (org.springframework.context.annotation.Lazy)4 AbstractJpaProperties (org.apereo.cas.configuration.model.support.jpa.AbstractJpaProperties)2 DatabaseProperties (org.apereo.cas.configuration.model.support.jpa.DatabaseProperties)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Primary (org.springframework.context.annotation.Primary)2 DefaultPersistenceUnitManager (org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager)2 DatabaseManager (com.fredboat.backend.quarterdeck.db.DatabaseManager)1 AugmentableQueryRepositoryFactoryBean (com.thinkbiganalytics.metadata.jpa.feed.AugmentableQueryRepositoryFactoryBean)1 DataSourceBean (de.alpharogroup.springconfig.DataSourceBean)1 JdbcUrlBean (de.alpharogroup.springconfig.JdbcUrlBean)1 PersistenceUnitInfo (jakarta.persistence.spi.PersistenceUnitInfo)1