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

The following examples show how to use org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#setPersistenceUnitName() . 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: JpaTransactionManagerConfiguration.java    From hypersistence-optimizer with Apache License 2.0 7 votes vote down vote up
@Bean
public EntityManagerFactory entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setPersistenceUnitName(persistenceUnitName());
    entityManagerFactoryBean.setPersistenceProvider(new HibernatePersistence());
    entityManagerFactoryBean.setDataSource(dataSource());
    entityManagerFactoryBean.setPackagesToScan(packagesToScan());

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

    entityManagerFactoryBean.afterPropertiesSet();

    return HypersistenceHibernatePersistenceProvider.decorate(
        entityManagerFactoryBean.getNativeEntityManagerFactory()
    );
}
 
Example 2
Source File: Utils.java    From radman with MIT License 6 votes vote down vote up
static LocalContainerEntityManagerFactoryBean buildEntityManager(DataSource dataSource,
                                                                 JpaProperties jpaProperties,
                                                                 String entitiesPackage,
                                                                 String persistenceUnitName) {
    LocalContainerEntityManagerFactoryBean entityManager = new LocalContainerEntityManagerFactoryBean();
    entityManager.setDataSource(dataSource);
    entityManager.setPackagesToScan(entitiesPackage);
    entityManager.setPersistenceUnitName(persistenceUnitName);
    entityManager.setJpaVendorAdapter(new HibernateJpaVendorAdapter());

    HashMap<String, Object> properties = new HashMap<>();
    properties.put("hibernate.hbm2ddl.auto", jpaProperties.getHibernate().getDdlAuto());
    properties.put("hibernate.dialect", jpaProperties.getHibernate().getDialect());
    properties.put("show-sql", jpaProperties.getShowSql());

    entityManager.setJpaPropertyMap(properties);
    return entityManager;
}
 
Example 3
Source File: DatabaseConfiguration.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Bean
public EntityManagerFactory entityManagerFactory() {
    log.debug("Configuring EntityManager");
    LocalContainerEntityManagerFactoryBean lcemfb = new LocalContainerEntityManagerFactoryBean();
    lcemfb.setPersistenceProvider(new HibernatePersistence());
    lcemfb.setPersistenceUnitName("persistenceUnit");
    lcemfb.setDataSource(dataSource());
    lcemfb.setJpaDialect(new HibernateJpaDialect());
    lcemfb.setJpaVendorAdapter(jpaVendorAdapter());

    Properties jpaProperties = new Properties();
    jpaProperties.put("hibernate.cache.use_second_level_cache", false);
    jpaProperties.put("hibernate.generate_statistics", env.getProperty("hibernate.generate_statistics", Boolean.class, false));
    lcemfb.setJpaProperties(jpaProperties);

    lcemfb.setPackagesToScan("com.activiti.domain");
    lcemfb.afterPropertiesSet();
    return lcemfb.getObject();
}
 
Example 4
Source File: CustomerConfig.java    From spring-boot-jta-atomikos-sample with Apache License 2.0 6 votes vote down vote up
@Primary
@Bean(name = "customerEntityManager")
@DependsOn("transactionManager")
public LocalContainerEntityManagerFactoryBean customerEntityManager() throws Throwable {

	HashMap<String, Object> properties = new HashMap<String, Object>();
	properties.put("hibernate.transaction.jta.platform", AtomikosJtaPlatform.class.getName());
	properties.put("javax.persistence.transactionType", "JTA");

	LocalContainerEntityManagerFactoryBean entityManager = new LocalContainerEntityManagerFactoryBean();
	entityManager.setJtaDataSource(customerDataSource());
	entityManager.setJpaVendorAdapter(jpaVendorAdapter);
	entityManager.setPackagesToScan("com.iyihua.sample.domain.customer");
	entityManager.setPersistenceUnitName("customerPersistenceUnit");
	entityManager.setJpaPropertyMap(properties);
	return entityManager;
}
 
Example 5
Source File: DataSourceConfig.java    From careconnect-reference-implementation with Apache License 2.0 6 votes vote down vote up
@Bean
public EntityManagerFactory entityManagerFactory() {
  //  final Database database = Database.valueOf(vendor.toUpperCase());

    final LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setPersistenceUnitName("CCRI_PERSISTENCE_UNIT");
   // factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("uk.nhs.careconnect.ri.database.entity");
    factory.setDataSource(dataSource());
    factory.setPersistenceProvider(new HibernatePersistenceProvider());
    factory.setJpaProperties(jpaProperties());
    factory.afterPropertiesSet();


    return factory.getObject();
}
 
Example 6
Source File: EntityManagerFactoryServiceImpl.java    From multitenant with Apache License 2.0 6 votes vote down vote up
@Override
public EntityManagerFactory createEntityManagerFactory(Organization organization) {
	DataSource dataSource = dataSourceService.getOrCreateDataSource(organization);
	Map<String, Object> vendorProperties = getVendorProperties(dataSource);
	customizeVendorProperties(vendorProperties);
	LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = getEntityManagerFactoryBuilder(dataSource).dataSource(dataSource).packages(mergePackagesToScan())
			.properties(vendorProperties).jta(isJta()).build();
	entityManagerFactoryBean.setBeanClassLoader(classLoader);
	entityManagerFactoryBean.setBeanFactory(beanFactory);
	entityManagerFactoryBean.setBeanName(beanName);
	entityManagerFactoryBean.setLoadTimeWeaver(loadTimeWeaver);
	entityManagerFactoryBean.setResourceLoader(resourceLoader);
	entityManagerFactoryBean.setPersistenceUnitName(organization.getId());
	entityManagerFactoryBean.afterPropertiesSet();
	scriptService.runScripts(organization.getId(), dataSource, dataScript, "multitenant-data");
	return entityManagerFactoryBean.getObject();
}
 
Example 7
Source File: DatabaseConfiguration.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Bean(name = "entityManagerFactory")
public EntityManagerFactory entityManagerFactory(DataSource dataSource) {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setDataSource(dataSource);
    entityManagerFactoryBean.setPackagesToScan("org.flowable.rest.api.jpa.model");
    entityManagerFactoryBean.setPersistenceUnitName("test");
    HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
    hibernateJpaVendorAdapter.setShowSql(false);
    hibernateJpaVendorAdapter.setGenerateDdl(true);
    hibernateJpaVendorAdapter.setDatabase(Database.H2);
    entityManagerFactoryBean.setJpaVendorAdapter(hibernateJpaVendorAdapter);
    entityManagerFactoryBean.afterPropertiesSet();
    return entityManagerFactoryBean.getObject();
}
 
Example 8
Source File: ReplicationDataSourceApplicationConfig.java    From replication-datasource with Apache License 2.0 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(@Qualifier("dataSource") DataSource dataSource) {
    LocalContainerEntityManagerFactoryBean emfb = new LocalContainerEntityManagerFactoryBean();
    emfb.setDataSource(dataSource);
    emfb.setPersistenceUnitName("replicationTest");
    JpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
    emfb.setJpaVendorAdapter(jpaVendorAdapter);
    return emfb;
}
 
Example 9
Source File: JTATransactionManagerConfiguration.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Bean
@DependsOn("btmConfig")
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    localContainerEntityManagerFactoryBean.setPersistenceUnitName(getClass().getSimpleName());
    localContainerEntityManagerFactoryBean.setPersistenceProvider(new HibernatePersistenceProvider());
    localContainerEntityManagerFactoryBean.setJtaDataSource(dataSource());
    localContainerEntityManagerFactoryBean.setPackagesToScan(packagesToScan());

    JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    localContainerEntityManagerFactoryBean.setJpaVendorAdapter(vendorAdapter);
    localContainerEntityManagerFactoryBean.setJpaProperties(additionalProperties());
    return localContainerEntityManagerFactoryBean;
}
 
Example 10
Source File: AemJpaConfiguration.java    From jwala with Apache License 2.0 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean getEntityManagerFactoryBean(final DataSource dataSource) {

    final LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setDataSource(dataSource);
    factory.setJpaVendorAdapter(new OpenJpaVendorAdapter());
    factory.setPersistenceUnitName("jwala-unit");
    factory.setPersistenceXmlLocation("classpath:META-INF/persistence.xml");

    return factory;
}
 
Example 11
Source File: AbstractFlywayConfiguration.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Bean @DependsOn("flyway")
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    localContainerEntityManagerFactoryBean.setPersistenceUnitName(getClass().getSimpleName());
    localContainerEntityManagerFactoryBean.setPersistenceProvider(new HibernatePersistenceProvider());
    localContainerEntityManagerFactoryBean.setDataSource(dataSource());
    localContainerEntityManagerFactoryBean.setPackagesToScan(packagesToScan());

    JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    localContainerEntityManagerFactoryBean.setJpaVendorAdapter(vendorAdapter);
    localContainerEntityManagerFactoryBean.setJpaProperties(additionalProperties());
    return localContainerEntityManagerFactoryBean;
}
 
Example 12
Source File: JPATransactionManagerConfiguration.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setPersistenceUnitName(getClass().getSimpleName());
    entityManagerFactoryBean.setPersistenceProvider(new HibernatePersistenceProvider());
    entityManagerFactoryBean.setDataSource(dataSource());
    entityManagerFactoryBean.setPackagesToScan(packagesToScan());

    JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    entityManagerFactoryBean.setJpaVendorAdapter(vendorAdapter);
    entityManagerFactoryBean.setJpaProperties(additionalProperties());
    return entityManagerFactoryBean;
}
 
Example 13
Source File: JpaTestConfig.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean getLocalContainerEntityManagerFactoryBean() {
	LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();
	bean.setJpaProperties(hibernateProperties());
	bean.setPackagesToScan(TestEntity.class.getPackage().getName());
	bean.setDataSource(testDataSource());
	bean.setPersistenceUnitName("TEST");
	return bean;
}
 
Example 14
Source File: FhirServerConfigR4.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 15
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 16
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 17
Source File: AbstractJPAConfiguration.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setPersistenceUnitName(getClass().getSimpleName());
    entityManagerFactoryBean.setPersistenceProvider(new HibernatePersistenceProvider());
    entityManagerFactoryBean.setDataSource(dataSource());
    entityManagerFactoryBean.setPackagesToScan(packagesToScan());

    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    HibernateJpaDialect jpaDialect = vendorAdapter.getJpaDialect();
    jpaDialect.setPrepareConnection(false);
    entityManagerFactoryBean.setJpaVendorAdapter(vendorAdapter);
    entityManagerFactoryBean.setJpaProperties(additionalProperties());
    return entityManagerFactoryBean;
}
 
Example 18
Source File: ReplicationDataSourceApplicationConfig.java    From replication-datasource with Apache License 2.0 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(@Qualifier("dataSource") DataSource dataSource) {
    LocalContainerEntityManagerFactoryBean emfb = new LocalContainerEntityManagerFactoryBean();
    emfb.setDataSource(dataSource);
    emfb.setPersistenceUnitName("replicationTest");
    JpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
    emfb.setJpaVendorAdapter(jpaVendorAdapter);
    return emfb;
}
 
Example 19
Source File: OrderConfig.java    From spring-boot-jta-atomikos-sample with Apache License 2.0 5 votes vote down vote up
@Bean(name = "orderEntityManager")
public LocalContainerEntityManagerFactoryBean orderEntityManager() throws Throwable {

	HashMap<String, Object> properties = new HashMap<String, Object>();
	properties.put("hibernate.transaction.jta.platform", AtomikosJtaPlatform.class.getName());
	properties.put("javax.persistence.transactionType", "JTA");

	LocalContainerEntityManagerFactoryBean entityManager = new LocalContainerEntityManagerFactoryBean();
	entityManager.setJtaDataSource(orderDataSource());
	entityManager.setJpaVendorAdapter(jpaVendorAdapter);
	entityManager.setPackagesToScan("com.iyihua.sample.domain.order");
	entityManager.setPersistenceUnitName("orderPersistenceUnit");
	entityManager.setJpaPropertyMap(properties);
	return entityManager;
}
 
Example 20
Source File: JPAStartupService.java    From lutece-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Initialize JPA objects (Datasource, Persistence Unit Manager, Entity Manager Factory, Transaction Manager) for each pool.
 */
public void process( )
{
    ReferenceList list = new ReferenceList( );
    AppConnectionService.getPoolList( list );

    Map<String, EntityManagerFactory> mapFactories = new HashMap<>( );
    List<PlatformTransactionManager> listTransactionManagers = new ArrayList<>( );
    _log.info( "JPA Startup Service : Initializing JPA objects ..." );

    String strDialectProperty = AppPropertiesService.getProperty( JPA_DIALECT_PROPERTY );

    for ( ReferenceItem poolItem : list )
    {
        String strPoolname = poolItem.getCode( );

        DataSource ds = AppConnectionService.getPoolManager( ).getDataSource( strPoolname );
        _log.info( "JPA Startup Service : DataSource retrieved for pool : " + strPoolname );
        _log.debug( "> DS : " + ds.toString( ) );

        DefaultPersistenceUnitManager pum = new DefaultPersistenceUnitManager( );
        pum.setDefaultDataSource( ds );

        PersistenceUnitPostProcessor [ ] postProcessors = {
                new JPAPersistenceUnitPostProcessor( )
        };
        pum.setPersistenceUnitPostProcessors( postProcessors );

        pum.afterPropertiesSet( );

        _log.info( "JPA Startup Service : Persistence Unit Manager for pool : " + strPoolname );
        _log.debug( "> PUM : " + pum.toString( ) );

        LocalContainerEntityManagerFactoryBean lcemfb = new LocalContainerEntityManagerFactoryBean( );
        lcemfb.setDataSource( ds );
        lcemfb.setPersistenceUnitManager( pum );
        lcemfb.setPersistenceUnitName( "jpaLuteceUnit" );

        JpaDialect jpaDialect = SpringContextService.getBean( "jpaDialect" );
        lcemfb.setJpaDialect( jpaDialect );

        Map mapJpaProperties = SpringContextService.getBean( "jpaPropertiesMap" );
        lcemfb.setJpaPropertyMap( mapJpaProperties );

        String strDialect = AppPropertiesService.getProperty( poolItem.getName( ) + ".dialect" );

        // replace default dialect if <poolname>.dialect is specified
        if ( StringUtils.isNotBlank( strDialect ) )
        {
            mapJpaProperties.put( strDialectProperty, strDialect );
        }

        _log.debug( "Using dialect " + mapJpaProperties.get( strDialectProperty ) + " for pool " + poolItem.getName( ) );

        JpaVendorAdapter jpaVendorAdapter = SpringContextService.getBean( "jpaVendorAdapter" );
        lcemfb.setJpaVendorAdapter( jpaVendorAdapter );

        lcemfb.afterPropertiesSet( );

        EntityManagerFactory emf = lcemfb.getNativeEntityManagerFactory( );
        _log.info( "JPA Startup Service : EntityManagerFactory created for pool : " + strPoolname );
        _log.debug( "> EMF : " + emf.toString( ) );

        JpaTransactionManager tm = new JpaTransactionManager( );
        tm.setEntityManagerFactory( emf );
        tm.setJpaDialect( jpaDialect );
        _log.debug( "> JpaDialect " + jpaDialect );
        tm.afterPropertiesSet( );
        _log.info( "JPA Startup Service : JPA TransactionManager created for pool : " + strPoolname );
        _log.debug( "> TM : " + tm.toString( ) );

        mapFactories.put( strPoolname, emf );
        listTransactionManagers.add( tm );
    }

    EntityManagerService ems = SpringContextService.getBean( "entityManagerService" );
    ems.setMapFactories( mapFactories );

    ChainedTransactionManager ctm = SpringContextService.getBean( "transactionManager" );
    ctm.setTransactionManagers( listTransactionManagers );
    _log.info( "JPA Startup Service : completed successfully" );
}