Example usage for org.springframework.orm.jpa LocalContainerEntityManagerFactoryBean LocalContainerEntityManagerFactoryBean

List of usage examples for org.springframework.orm.jpa LocalContainerEntityManagerFactoryBean LocalContainerEntityManagerFactoryBean

Introduction

In this page you can find the example usage for org.springframework.orm.jpa LocalContainerEntityManagerFactoryBean LocalContainerEntityManagerFactoryBean.

Prototype

LocalContainerEntityManagerFactoryBean

Source Link

Usage

From source file:edu.chalmers.dat076.moviefinder.test.config.TestRepositoryConfig.java

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {

    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setDatabase(Database.HSQL);
    vendorAdapter.setGenerateDdl(true);/*ww  w  .  ja  va2  s.  co m*/

    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("edu.chalmers.dat076.moviefinder.persistence");
    factory.setDataSource(dataSource());

    return factory;
}

From source file:org.teavm.flavour.example.server.ApplicationConfiguration.java

@Bean
public FactoryBean<EntityManagerFactory> entityManagerFactory(DataSource dataSource) {
    LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
    emf.setDataSource(dataSource);/*  w w  w. java 2 s.c  o m*/
    emf.setPersistenceUnitName("PU");
    emf.setPackagesToScan("org.teavm.flavour.example.model");
    emf.setPersistenceProviderClass(PersistenceProvider.class);

    Map<String, String> properties = new HashMap<>();
    properties.put("eclipselink.weaving", "false");
    properties.put("eclipselink.ddl-generation", "create-or-extend-tables");
    emf.setJpaPropertyMap(properties);

    return emf;
}

From source file:org.ameba.samples.tenancy.TenancyEclipseLinkSampleApplication.java

@Bean
public EntityManagerFactory entityManagerFactory(DataSource dataSource) {
    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setDataSource(dataSource);//from   ww  w.  j av a 2 s  . c  om
    factory.setJpaVendorAdapter(new EclipseLinkJpaVendorAdapter());
    factory.setPackagesToScan(TenancyEclipseLinkSampleApplication.class.getPackage().getName());
    factory.getJpaPropertyMap().put(PersistenceUnitProperties.DDL_GENERATION_MODE,
            PersistenceUnitProperties.DDL_DATABASE_GENERATION);
    factory.getJpaPropertyMap().put(PersistenceUnitProperties.LOGGING_LEVEL, "FINE");
    factory.getJpaPropertyMap().put(PersistenceUnitProperties.WEAVING, "false");
    factory.getJpaPropertyMap().put(TenantHolder.TENANT_ID, TenantHolder.getTenant());
    factory.afterPropertiesSet();
    return factory.getObject();
}

From source file:nl.amc.ebioscience.ecat.EcatConfig.java

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource,
        JpaVendorAdapter jpaVendorAdapter) {

    LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
    lef.setDataSource(dataSource);//from   www  . ja  v  a  2 s.  c o  m
    lef.setJpaVendorAdapter(jpaVendorAdapter);
    lef.setPackagesToScan("nl.amc.ebioscience.ecat.model");

    return lef;
}

From source file:au.com.shawware.sandbox.persistence.JPAConfiguration.java

/**
 * Defines the entity manager factory to use.
 * // w w  w . j a v  a 2 s . c o m
 * @return the entity manager factory bean
 * 
 * @throws SQLException error creating the bean
 */
@Bean
public EntityManagerFactory entityManagerFactory() throws SQLException {
    final HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
    adapter.setShowSql(true);
    adapter.setGenerateDdl(true);
    //        adapter.setDatabase(Database.HSQL);

    final LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(adapter);
    factory.setPackagesToScan(Node.class.getPackage().getName());
    factory.setDataSource(dataSource());

    final Properties jpaProperties = new Properties();
    jpaProperties.setProperty("hibernate.show_sql", "true"); // redundant?
    jpaProperties.setProperty("hibernate.format_sql", "true");
    jpaProperties.setProperty("hibernate.hbm2ddl.auto", "create");
    jpaProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
    jpaProperties.setProperty("hibernate.connection.pool_size", "0");
    //        jpaProperties.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
    //        jpaProperties.setProperty("hibernate.hibernate.transaction.factory_class", "org.hibernate.transaction.JDBCTransactionFactory");
    jpaProperties.setProperty("hibernate.connection.url", "jdbc:hsqldb:file:target/data/test;shutdown=true");
    jpaProperties.setProperty("hibernate.connection.username", "sa");
    jpaProperties.setProperty("hibernate.connection.password", "");
    jpaProperties.setProperty("hibernate.connection.autocommit", "true");
    jpaProperties.setProperty("hibernate.jdbc.batch_size", "0");
    jpaProperties.setProperty("hibernate.ejb.entitymanager_factory_name", "sandbox");
    factory.setJpaProperties(jpaProperties);

    // The following method call is important. Things break without it.
    factory.afterPropertiesSet();

    return factory.getObject();
}

From source file:ru.portal.services.AppConfigTest.java

@Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {

    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setShowSql(true);//from w ww . jav a 2  s. com

    LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(this.dataSource());
    em.setPackagesToScan(new String[] { "ru.portal.entity" });
    em.setPersistenceUnitName("portalPersistanceUnit");

    em.setJpaVendorAdapter(vendorAdapter);
    em.setJpaProperties(additionalProperties());

    em.afterPropertiesSet();

    return em;

}

From source file:gov.nih.nci.cacis.xds.authz.config.JpaConfig.java

/**
 * Entity manager factory./*from   w  w w.j  a  v a 2s  .c  om*/
 *
 * @return the entity manager factory
 */
@Bean(name = "entityManagerFactory")
public EntityManagerFactory entityManagerFactory() {
    final LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setPersistenceUnitName(PERSISTENCE_UNIT_NAME);
    entityManagerFactoryBean.setDataSource(dataSource());
    entityManagerFactoryBean.setJpaVendorAdapter(jpaVendorAdapter());
    entityManagerFactoryBean.setPersistenceXmlLocation("classpath*:META-INF/xds-beans-persistence.xml");

    // must set the properties
    entityManagerFactoryBean.afterPropertiesSet();
    return entityManagerFactoryBean.getObject();
}

From source file:fredboat.db.DatabaseManager.java

/**
 * @param jdbcUrl connection to the database
 * @param dialect set to null or empty String to have it autodetected by Hibernate, chosen jdbc driver must support that
 *//* w w w . ja va 2s.  co m*/
public static void startup(String jdbcUrl, String dialect, int poolSize) {
    state = DatabaseState.INITIALIZING;

    try {

        if (Config.CONFIG.isUseSshTunnel()) {
            connectSSH();
        }

        //These are now located in the resources directory as XML
        Properties properties = new Properties();
        properties.put("configLocation", "hibernate.cfg.xml");

        properties.put("hibernate.connection.provider_class",
                "org.hibernate.hikaricp.internal.HikariCPConnectionProvider");
        properties.put("hibernate.connection.url", jdbcUrl);
        if (dialect != null && !"".equals(dialect))
            properties.put("hibernate.dialect", dialect);
        properties.put("hibernate.cache.region.factory_class",
                "org.hibernate.cache.ehcache.EhCacheRegionFactory");

        //properties.put("hibernate.show_sql", "true");

        //automatically update the tables we need
        //caution: only add new columns, don't remove or alter old ones, otherwise manual db table migration needed
        properties.put("hibernate.hbm2ddl.auto", "update");

        properties.put("hibernate.hikari.maximumPoolSize", Integer.toString(poolSize));
        properties.put("hibernate.hikari.idleTimeout", Integer.toString(Config.HIKARI_TIMEOUT_MILLISECONDS));

        LocalContainerEntityManagerFactoryBean emfb = new LocalContainerEntityManagerFactoryBean();
        emfb.setPackagesToScan("fredboat.db.entity");
        emfb.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
        emfb.setJpaProperties(properties);
        emfb.setPersistenceUnitName("fredboat.test");
        emfb.setPersistenceProviderClass(HibernatePersistenceProvider.class);
        emfb.afterPropertiesSet();
        emf = emfb.getObject();

        log.info("Started Hibernate");
        state = DatabaseState.READY;
    } catch (Exception ex) {
        state = DatabaseState.FAILED;
        throw new RuntimeException("Failed starting database connection", ex);
    }
}

From source file:br.com.proj.web.config.WebMvcConfig.java

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    System.out.println("entityManagerFactory");
    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();

    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setGenerateDdl(Boolean.TRUE);
    vendorAdapter.setShowSql(Boolean.TRUE);

    factory.setDataSource(dataSource());
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("br.com.proj.model");

    Properties jpaProperties = new Properties();
    jpaProperties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
    factory.setJpaProperties(jpaProperties);

    factory.afterPropertiesSet();//from ww  w . jav  a 2s. c o  m
    factory.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
    return factory;
}

From source file:org.raistlic.spring.test.flyway.FlywayTestConfiguration.java

@Bean
@Autowired//from   ww  w  .  j  a  va 2 s  .com
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource,
        JpaVendorAdapter jpaVendorAdapter) {

    LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
    factoryBean.setDataSource(dataSource);
    factoryBean.setJpaVendorAdapter(jpaVendorAdapter);
    factoryBean.setPackagesToScan("org.raistlic.spring.test.flyway.sample");
    return factoryBean;
}