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

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

Introduction

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

Prototype

@Override
    public void afterPropertiesSet() throws PersistenceException 

Source Link

Usage

From source file:org.surfnet.oaaas.repository.AbstractTestRepository.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private static EntityManager entityManager(DataSource dataSource) {
    LocalContainerEntityManagerFactoryBean emfBean = new LocalContainerEntityManagerFactoryBean();
    emfBean.setDataSource(dataSource);/*from   www.j  av  a  2  s .com*/
    emfBean.setPersistenceUnitName(PERSISTENCE_UNIT_NAME);
    emfBean.setPersistenceProviderClass(PERSISTENCE_PROVIDER_CLASS);
    emfBean.afterPropertiesSet();
    Map map = new HashMap<String, String>();
    map.put("openjpa.ConnectionFactoryProperties", "PrintParameters=true");
    return emfBean.getObject().createEntityManager(map);
}

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
 *//*from  w w w .j  a  v a2s.c  o  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:corner.orm.gae.GaeModule.java

public static EntityManagerFactory buildEntityManagerFactory(
        @Autobuild DatastorePersistenceProvider persistenceProvider) {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setPersistenceProvider(persistenceProvider);
    Properties jpaProperties = new Properties();
    jpaProperties.put("datanucleus.NontransactionalRead", "true");
    jpaProperties.put("datanucleus.NontransactionalWrite", "true");
    jpaProperties.put("datanucleus.ConnectionURL", "appengine");
    jpaProperties.put("datanucleus.jpa.addClassTransformer", "false");
    entityManagerFactoryBean.setJpaProperties(jpaProperties);
    LoadTimeWeaver loadTimeWeaver = new SimpleLoadTimeWeaver();
    entityManagerFactoryBean.setLoadTimeWeaver(loadTimeWeaver);
    entityManagerFactoryBean.afterPropertiesSet();
    return entityManagerFactoryBean.getObject();
}

From source file:org.ops4j.pax.exam.regression.web.spring.TestSpringConfig.java

@Bean
public EntityManagerFactory entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();
    bean.setDataSource(dataSource());//from   ww w .  ja  v a 2 s. co  m
    bean.setPersistenceXmlLocation("classpath:META-INF/persistence.xml");
    bean.afterPropertiesSet();
    return bean.getObject();
}

From source file:com.gopivotal.cla.repository.RepositoryConfiguration.java

@Bean
EntityManagerFactory entityManagerFactory() {
    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();

    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setDataSource(dataSource());
    factory.afterPropertiesSet();

    return factory.getObject();
}

From source file:br.com.gumga.academia.aplicacao.Aplicacao.java

@Bean
public EntityManagerFactory entityManagerFactory() {

    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setGenerateDdl(true);//w  w  w.j a  v a2  s .c o m

    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("br.com.gumga.academia.entidades");
    factory.setDataSource(dataSource());
    factory.afterPropertiesSet();

    return factory.getObject();
}

From source file:br.com.gumga.academia.Aplicacao.java

@Bean
public EntityManagerFactory entityManagerFactory() {

    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setGenerateDdl(true);//from w ww  .j  a v a2  s.  c o  m

    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("br.com.gumga.academia.entidade");
    factory.setDataSource(dataSource());
    factory.afterPropertiesSet();

    return factory.getObject();
}

From source file:things.Application.java

@Bean
public EntityManagerFactory entityManagerFactory() {

    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setGenerateDdl(true);/*from w  w  w .  jav  a2  s. c  o m*/

    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("things.thing");
    factory.setDataSource(dataSource());
    factory.afterPropertiesSet();

    return factory.getObject();
}

From source file:com.example.spring.boot.app.RepositoryConfig.java

@Bean
public EntityManagerFactory entityManagerFactory() {
    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setGenerateDdl(true);//ww  w . ja v  a2  s  .  c o  m

    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan(User.class.getPackage().getName());
    factory.setDataSource(dataSource());
    factory.afterPropertiesSet();

    return factory.getObject();
}

From source file:org.oncoblocks.centromere.jpa.test.JpaTestConfig.java

@Bean
public EntityManagerFactory entityManagerFactory() {
    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setGenerateDdl(false);
    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("org.oncoblocks.centromere.jpa.test");
    factory.setDataSource(dataSource());
    factory.afterPropertiesSet();
    return factory.getObject();
}