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:org.activiti.spring.test.jpa.JPASpringTest.java

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean(
        OpenJpaVendorAdapter openJpaVendorAdapter, DataSource ds) {
    LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
    emf.setPersistenceXmlLocation("classpath:/org/activiti/spring/test/jpa/custom-persistence.xml");
    emf.setJpaVendorAdapter(openJpaVendorAdapter);
    emf.setDataSource(ds);/*from w w w. j  av a 2  s  . c  o  m*/
    return emf;
}

From source file:org.unitils.orm.jpa.util.JpaEntityManagerFactoryLoader.java

/**
 * @param testObject The test instance, not null
 * @param jpaConfig  The configuration parameters for the <code>EntityManagerFactory</code>
 * @return A completely configured <code>AbstractEntityManagerFactoryBean</code>
 *//*  w w  w .  j  a v  a2s.  c  om*/
protected AbstractEntityManagerFactoryBean createEntityManagerFactoryBean(Object testObject,
        JpaConfig jpaConfig) {
    LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
    factoryBean.setDataSource(getDataSource());
    factoryBean.setJpaVendorAdapter(getJpaProviderSupport().getSpringJpaVendorAdaptor());
    String persistenceXmlFile = jpaConfig.getConfigFiles().iterator().next();
    if (!StringUtils.isEmpty(persistenceXmlFile)) {
        factoryBean.setPersistenceXmlLocation(persistenceXmlFile);
    }
    factoryBean.setPersistenceUnitName(jpaConfig.getPersistenceUnitName());
    LoadTimeWeaver loadTimeWeaver = getJpaProviderSupport().getLoadTimeWeaver();
    if (loadTimeWeaver != null) {
        factoryBean.setLoadTimeWeaver(loadTimeWeaver);
    }
    if (jpaConfig.getConfigMethod() != null) {
        try {
            ReflectionUtils.invokeMethod(testObject, jpaConfig.getConfigMethod(), factoryBean);
        } catch (InvocationTargetException e) {
            throw new UnitilsException("Error while invoking custom config method", e.getCause());
        }
    }
    factoryBean.afterPropertiesSet();
    return factoryBean;
}