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

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

Introduction

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

Prototype

public void setPersistenceXmlLocation(String persistenceXmlLocation) 

Source Link

Document

Set the location of the persistence.xml file we want to use.

Usage

From source file:com.qpark.eip.core.spring.lockedoperation.config.EipLockedoperationConfig.java

/**
 * Get the {@link LocalContainerEntityManagerFactoryBean}.
 *
 * @return the {@link LocalContainerEntityManagerFactoryBean}.
 *//*from  ww w.  j a  v  a 2 s .com*/
@Bean(name = ENTITY_MANAGER_FACTORY_NAME)
public EntityManagerFactory getEntityManagerFactory() {
    AbstractJpaVendorAdapter jpaVendorAdapter = this.getJpaVendorAdapter();
    if (jpaVendorAdapter == null) {
        throw new RuntimeException(String.format("%s jpaVendorAdpater not set properly %s.",
                ENTITY_MANAGER_FACTORY_NAME, String.valueOf(jpaVendorAdapter)));
    }

    String jpaVendorAdapterDatabasePlatform = this.jpaVendorAdapterConfiguration
            .getJpaVendorAdpaterDatabasePlatform();
    if (jpaVendorAdapterDatabasePlatform == null || jpaVendorAdapterDatabasePlatform.trim().length() == 0) {
        throw new RuntimeException(String.format("%s jpaVendorAdpaterDatabasePlatform not set properly %s.",
                ENTITY_MANAGER_FACTORY_NAME, String.valueOf(jpaVendorAdapterDatabasePlatform)));
    }

    LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();
    bean.setPersistenceXmlLocation(new StringBuffer(96).append("classpath:/META-INF/")
            .append(PERSISTENCE_UNIT_NAME).append("/persistence.xml").toString());
    bean.setPersistenceUnitName(PERSISTENCE_UNIT_NAME);
    bean.setDataSource(this.datasource);

    jpaVendorAdapter.setDatabasePlatform(jpaVendorAdapterDatabasePlatform);
    jpaVendorAdapter.setShowSql(false);
    if (this.isJpaVendorAdapterGenerateDdl()) {
        jpaVendorAdapter.setGenerateDdl(true);
        if (HibernateJpaVendorAdapter.class.isInstance(jpaVendorAdapter)) {
            bean.getJpaPropertyMap().put("hibernate.hbm2ddl.auto", "update");
        }
    } else {
        jpaVendorAdapter.setGenerateDdl(false);
    }

    bean.setJpaVendorAdapter(jpaVendorAdapter);
    bean.afterPropertiesSet();
    return bean.getObject();
}

From source file:org.wte4j.ui.server.services.IntegrationTestConfiguration.java

@Bean
@Qualifier("wte4j")
public LocalContainerEntityManagerFactoryBean wteEntityManagerFactory() {
    LocalContainerEntityManagerFactoryBean emfFactoryBean = new LocalContainerEntityManagerFactoryBean();
    emfFactoryBean.setDataSource(dataSource());
    emfFactoryBean.setJpaVendorAdapter(new OpenJpaVendorAdapter());
    emfFactoryBean.setPersistenceXmlLocation("classpath:/test-persistence.xml");
    emfFactoryBean.setPersistenceUnitName("wte4j-templates");
    emfFactoryBean.setJpaPropertyMap(createJpaPropertyMap());
    return emfFactoryBean;
}

From source file:org.csc.phynixx.spring.integration.config.BitronixPersistenceConfig.java

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws Exception {
    final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setJtaDataSource(this.dataSource());
    em.setPersistenceUnitName("test");
    em.setPersistenceXmlLocation("classpath:META-INF/bitronix-persistence.xml");
    em.setPackagesToScan(ItemData.class.getPackage().getName());

    final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setDatabasePlatform(this.hibernateDialect());
    vendorAdapter.setShowSql(this.hibernateShowSql());

    em.setJpaVendorAdapter(vendorAdapter);
    em.setJpaProperties(this.jpaProperties());

    return em;//from  w  w w  . j  av  a2 s .  co m
}

From source file:cz.swi2.mendeluis.dataaccesslayer.core.DatabaseConfig.java

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean jpaFactoryBean = new LocalContainerEntityManagerFactoryBean();
    jpaFactoryBean.setDataSource(db());//  ww w  .jav  a 2  s .co m
    jpaFactoryBean.setJpaVendorAdapter(jpaVendorAdapter());
    jpaFactoryBean.setLoadTimeWeaver(instrumentationLoadTimeWeaver());
    jpaFactoryBean.setPersistenceXmlLocation("classpath:META-INF/persistence.xml");
    jpaFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class);
    jpaFactoryBean.setPackagesToScan("cz.swi2.mendeluis.dataaccesslayer.*");
    return jpaFactoryBean;
}

From source file:org.csc.phynixx.spring.integration.config.AtomikosPersistenceConfig.java

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws Exception {
    final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setJtaDataSource(this.dataSource());
    em.setPersistenceUnitName("test");
    em.setPersistenceXmlLocation("classpath:META-INF/atomikos-persistence.xml");
    em.setPackagesToScan(ItemData.class.getPackage().getName());

    final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setDatabasePlatform(this.hibernateDialect());
    vendorAdapter.setShowSql(this.hibernateShowSql());

    em.setJpaVendorAdapter(vendorAdapter);
    em.setJpaProperties(this.jpaProperties());

    return em;//w  ww  .ja  v  a  2s .co m
}

From source file:ru.anr.base.dao.AbstractJPADaoConfig.java

/**
 * Definition of {@link EntityManagerFactory}
 * //from   w w w  . j av  a 2s. c om
 * @return Bean instance
 */
@Bean(name = "entityManagerFactory")
public EntityManagerFactory entityManagerFactory() {

    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();

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

    return factory.getObject();
}

From source file:org.zlogic.vogon.web.PersistenceConfiguration.java

/**
 * Creates the entityManagerFactory//from   w  ww.  j  a va 2 s.  c om
 *
 * @return the entityManagerFactory
 */
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactory.setPersistenceUnitName("VogonPU"); //NOI18N
    entityManagerFactory.getJpaPropertyMap().putAll(getDatabaseConfiguration());
    entityManagerFactory.setPersistenceXmlLocation("classpath:META-INF/persistence.xml"); //NOI18N
    return entityManagerFactory;
}

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

/**
 * Entity manager factory./*from  w w w.j  a  v  a2 s.c o m*/
 *
 * @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:gov.nih.nci.integration.dao.JpaConfig.java

/**
 * Entity manager factory.//from w ww  . ja  v  a2  s .co m
 * 
 * @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/ihub-messages-persistence.xml");

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

From source file:cz.lbenda.coursing.client.ClientAppConfig.java

public @Bean EntityManagerFactory entityManagerFactory() {
    try {//from   w  w w  . jav a 2  s.co  m
        EclipseLinkJpaVendorAdapter vendorAdapter = new EclipseLinkJpaVendorAdapter();
        vendorAdapter.setDatabasePlatform("org.eclipse.persistence.platform.database.H2Platform");
        vendorAdapter.setShowSql(true);
        vendorAdapter.setGenerateDdl(true);
        EclipseLinkJpaDialect dialect = new EclipseLinkJpaDialect();
        dialect.setLazyDatabaseTransaction(true);

        LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
        factory.setJpaVendorAdapter(vendorAdapter);
        factory.setJpaDialect(dialect);
        factory.setPackagesToScan("cz.lbenda.coursing");
        factory.setDataSource(dataSource());
        factory.setPersistenceXmlLocation("classpath*:META-INF/persistence.xml");
        factory.setPersistenceUnitName("coursing");

        /*
        Map<String, String> prop = new HashMap<>();
        prop.put("eclipselink.deploy-on-startup", "true");
        prop.put("eclipselink.ddl-generation", "create-or-extend-tables");
        prop.put("eclipselink.ddl-generation.output-mode", "database");
        prop.put("eclipselink.create-ddl-jdbc-file-name", "create.sql");
        prop.put("eclipselink.weaving", "static");
        prop.put("eclipselink.weaving.lazy", "true");
        prop.put("eclipselink.weaving.internal", "true");
        prop.put("eclipselink.logging.level", "SEVERE");
        prop.put("eclipselink.query-results-cache.type", "WEAK");
        prop.put("eclipselink.jdbc.batch-writing", "JDBC");
        prop.put("eclipselink.jdbc.batch-writing.size", "1000");
                
        factory.setJpaPropertyMap(prop);
        */

        // factory.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
        factory.afterPropertiesSet();

        return factory.getObject();
    } catch (Exception e) {
        LOG.trace("Faild create entityManagerFactory", e);
        throw new RuntimeException("Faild create entityManagerFactory", e);
    }
}