Java Code Examples for org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#setDataSource()

The following examples show how to use org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#setDataSource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HibernateConfig.java    From spring-boot-multitenant with Apache License 2.0 6 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource,
    MultiTenantConnectionProvider multiTenantConnectionProviderImpl,
    CurrentTenantIdentifierResolver currentTenantIdentifierResolverImpl) {
  Map<String, Object> properties = new HashMap<>();
  properties.putAll(jpaProperties.getHibernateProperties(dataSource));
  properties.put(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
  properties.put(Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProviderImpl);
  properties.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolverImpl);

  LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
  em.setDataSource(dataSource);
  em.setPackagesToScan("com.srai");
  em.setJpaVendorAdapter(jpaVendorAdapter());
  em.setJpaPropertyMap(properties);
  return em;
}
 
Example 2
Source File: AppConfig.java    From Spring-Framework-Essentials with MIT License 6 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
        DataSource dataSource, JpaVendorAdapter jpaVendorAdapter) {

    Properties props = new Properties();
    props.setProperty("hibernate.format_sql", String.valueOf(true));
    
    LocalContainerEntityManagerFactoryBean emf =
            new LocalContainerEntityManagerFactoryBean();
    emf.setDataSource(dataSource);
    emf.setPackagesToScan("com.oreilly.entities");
    emf.setJpaVendorAdapter(jpaVendorAdapter);
    emf.setJpaProperties(props);

    return emf;
}
 
Example 3
Source File: EclipseLinkConfig.java    From logging-log4j-audit with Apache License 2.0 6 votes vote down vote up
@Bean
public EntityManagerFactory entityManagerFactory() {
    LOGGER.debug("Creating EclipseLink entity manager.");
    AbstractJpaVendorAdapter vendorAdapter = new EclipseLinkJpaVendorAdapter();
    vendorAdapter.setGenerateDdl(false);
    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    Properties properties = new Properties();
    properties.setProperty("eclipselink.weaving", "static");
    factory.setJpaProperties(properties);
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("org.apache.logging.log4j.catalog");
    factory.setDataSource(dataSourceConfig.dataSource());
    factory.afterPropertiesSet();

    return factory.getObject();
}
 
Example 4
Source File: DataStoreConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
    final LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();
    bean.setDataSource(dataSource);
    bean.setJpaVendorAdapter(jpaVendorAdapter());
    bean.setPackagesToScan("com.baeldung.springsecuredsockets");

    //Set properties on Hibernate
    Properties properties = new Properties();
    properties.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    properties.setProperty("hibernate.hbm2ddl.auto", "update");
    bean.setJpaProperties(properties);

    return bean;
}
 
Example 5
Source File: PersistenceJPAConfig.java    From Hands-On-High-Performance-with-Spring-5 with MIT License 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
	LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
	em.setDataSource(dataSource());
	em.setPackagesToScan(new String[] { "com.packt.springhighperformance.ch6.bankingapp.model" });

	JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
	em.setJpaVendorAdapter(vendorAdapter);
	em.setJpaProperties(additionalProperties());

	return em;
}
 
Example 6
Source File: DataConfig.java    From market with MIT License 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
	LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); // todo: EntityManagerFactoryBuilder ?
	em.setDataSource(dataSource);
	em.setPackagesToScan("market.domain");
	em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
	return em;
}
 
Example 7
Source File: FhirServerConfigDstu3.java    From hapi-fhir-jpaserver-starter with Apache License 2.0 5 votes vote down vote up
@Override
@Bean()
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean retVal = super.entityManagerFactory();
    retVal.setPersistenceUnitName("HAPI_PU");

    try {
        retVal.setDataSource(myDataSource);
    } catch (Exception e) {
        throw new ConfigurationException("Could not set the data source due to a configuration issue", e);
    }

    retVal.setJpaProperties(HapiProperties.getJpaProperties());
    return retVal;
}
 
Example 8
Source File: PersistenceJPAConfig.java    From Hands-On-High-Performance-with-Spring-5 with MIT License 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
	LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
	em.setDataSource(dataSource());
	em.setPackagesToScan(new String[] { "com.packt.springhighperformance.ch6.bankingapp.model" });

	JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
	em.setJpaVendorAdapter(vendorAdapter);
	em.setJpaProperties(additionalProperties());

	return em;
}
 
Example 9
Source File: SpringDataITest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
  final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
  vendorAdapter.setDatabase(Database.H2);
  vendorAdapter.setGenerateDdl(true);

  final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
  em.setDataSource(dataSource());
  em.setPackagesToScan("io.opentracing.contrib.specialagent.test.spring.data");
  em.setJpaVendorAdapter(vendorAdapter);
  return em;
}
 
Example 10
Source File: PersistenceTestConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    final LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
    emf.setDataSource(restDataSource());
    emf.setPackagesToScan(new String[] { "com.baeldung.persistence.model" });

    final JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    emf.setJpaVendorAdapter(vendorAdapter);
    emf.setJpaProperties(hibernateProperties());

    return emf;
}
 
Example 11
Source File: PersistenceJPAConfigL2Cache.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(dataSource());
    em.setPackagesToScan(getPackagesToScan());

    final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    em.setJpaVendorAdapter(vendorAdapter);
    em.setJpaProperties(additionalProperties());

    return em;
}
 
Example 12
Source File: PersistenceTransactionalTestConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(dataSource());
    em.setPackagesToScan(new String[] { "com.baeldung.persistence.model" });

    final JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    em.setJpaVendorAdapter(vendorAdapter);
    em.setJpaProperties(additionalProperties());

    return em;
}
 
Example 13
Source File: PersistenceConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(dataSource());
    em.setPackagesToScan(new String[] { "com.baeldung.persistence.model", "com.baeldung.springpagination.model" });

    final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    // vendorAdapter.set
    em.setJpaVendorAdapter(vendorAdapter);
    em.setJpaProperties(additionalProperties());

    return em;
}
 
Example 14
Source File: Application.java    From blog-examples with Apache License 2.0 5 votes vote down vote up
@Bean
public EntityManagerFactory entityManagerFactory() throws SQLException {
	HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
	vendorAdapter.setGenerateDdl(true);
	LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
	factory.setJpaVendorAdapter(vendorAdapter);
	factory.setPackagesToScan("com.mscharhag.springjooq.entity");
	factory.setDataSource(dataSource());
	factory.afterPropertiesSet();
	return factory.getObject();
}
 
Example 15
Source File: FhirServerConfigR4.java    From cqf-ruler with Apache License 2.0 5 votes vote down vote up
@Override
@Bean()
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean retVal = super.entityManagerFactory();
    retVal.setPersistenceUnitName(HapiProperties.getPersistenceUnitName());

    try {
        retVal.setDataSource(myDataSource);
    } catch (Exception e) {
        throw new ConfigurationException("Could not set the data source due to a configuration issue", e);
    }

    retVal.setJpaProperties(HapiProperties.getProperties());
    return retVal;
}
 
Example 16
Source File: FhirServerConfigDstu3.java    From cqf-ruler with Apache License 2.0 5 votes vote down vote up
@Override
@Bean()
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean retVal = super.entityManagerFactory();
    retVal.setPersistenceUnitName(HapiProperties.getPersistenceUnitName());

    try {
        retVal.setDataSource(myDataSource);
    } catch (Exception e) {
        throw new ConfigurationException("Could not set the data source due to a configuration issue", e);
    }

    retVal.setJpaProperties(HapiProperties.getProperties());
    return retVal;
}
 
Example 17
Source File: PersistenceProductAutoConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean productEntityManager() {
    final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(productDataSource());
    em.setPackagesToScan("com.baeldung.multipledb.model.product");

    final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    em.setJpaVendorAdapter(vendorAdapter);
    final HashMap<String, Object> properties = new HashMap<String, Object>();
    properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
    properties.put("hibernate.dialect", env.getProperty("hibernate.dialect"));
    em.setJpaPropertyMap(properties);

    return em;
}
 
Example 18
Source File: ScoreDatabaseContext.java    From score with Apache License 2.0 5 votes vote down vote up
@Bean
@DependsOn("liquibase")
LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
    //Init the IdentityManager
    SimpleHiloIdentifierGenerator.setDataSource(dataSource);

    //Now create the bean
    LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
    emf.setDataSource(dataSource);
    emf.setJpaProperties(jpaProperties());
    emf.setJpaVendorAdapter(jpaVendorAdapter());
    emf.setPersistenceProviderClass(HibernatePersistenceProvider.class);
    emf.setPackagesToScan("io.cloudslang");
    return emf;
}
 
Example 19
Source File: RedisClusterBaseApplication.java    From rqueue with Apache License 2.0 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
  HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
  vendorAdapter.setGenerateDdl(true);
  LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
  factory.setJpaVendorAdapter(vendorAdapter);
  factory.setPackagesToScan("com.github.sonus21.rqueue.test.entity");
  factory.setDataSource(dataSource());
  return factory;
}
 
Example 20
Source File: CustomerConfig.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
@Bean
LocalContainerEntityManagerFactoryBean customerEntityManagerFactory() {

	HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
	jpaVendorAdapter.setGenerateDdl(true);

	LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();

	factoryBean.setDataSource(customerDataSource());
	factoryBean.setJpaVendorAdapter(jpaVendorAdapter);
	factoryBean.setPackagesToScan(CustomerConfig.class.getPackage().getName());

	return factoryBean;
}