當前位置: 首頁>>代碼示例>>Java>>正文


Java LocalContainerEntityManagerFactoryBean類代碼示例

本文整理匯總了Java中org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean的典型用法代碼示例。如果您正苦於以下問題:Java LocalContainerEntityManagerFactoryBean類的具體用法?Java LocalContainerEntityManagerFactoryBean怎麽用?Java LocalContainerEntityManagerFactoryBean使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LocalContainerEntityManagerFactoryBean類屬於org.springframework.orm.jpa包,在下文中一共展示了LocalContainerEntityManagerFactoryBean類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: entityManagerFactory

import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; //導入依賴的package包/類
@Bean
public EntityManagerFactory entityManagerFactory() {
	LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
	emf.setDataSource(dataSource());
	emf.setPackagesToScan("io.github.azanx.shopping_list.domain");
	emf.setPersistenceUnitName("spring-jpa-unit");
	emf.setJpaVendorAdapter(getHibernateAdapter());
	Properties jpaProperties = new Properties();
	jpaProperties.put("hibernate.dialect", env.getProperty("hibernate.dialect"));
	jpaProperties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
	jpaProperties.put("hibernate.show_sql", env.getProperty("hibernate.show_sql"));
	jpaProperties.put("hibernate.format_sql", env.getProperty("hibernate.format_sql"));
	emf.setJpaProperties(jpaProperties);
	emf.afterPropertiesSet();
	return emf.getObject();
}
 
開發者ID:Azanx,項目名稱:Smart-Shopping,代碼行數:17,代碼來源:JPAConfig.java

示例2: newEntityManagerFactory

import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; //導入依賴的package包/類
public static EntityManagerFactory newEntityManagerFactory(DataSource dataSource, Class<?> ... entityPackages){
	HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
	vendorAdapter.setGenerateDdl(true);

	BasicDataSource basicDataSource = (BasicDataSource)dataSource;
	Database jpaDatabase = DatabaseType.findTypeByJdbcUrl(basicDataSource.getUrl()).getJpaDatabase();
	vendorAdapter.setDatabase(jpaDatabase);

	HashMap<String, Object> properties = new HashMap<String, Object>();
	//properties.put("hibernate.dialect", "org.hibernate.dialect.MySQL5InnoDBDialect");

	LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
	factory.setJpaVendorAdapter(vendorAdapter);
	//import @Entity classes
	factory.setPackagesToScan(Arrays.stream(entityPackages).map(thing -> thing.getPackage().getName()).toArray(String[]::new));
	//factory.setPersistenceUnitName("jproject");
	factory.setDataSource(dataSource);
	factory.setJpaPropertyMap(properties);
	factory.afterPropertiesSet();

	return factory.getObject();
}
 
開發者ID:profullstack,項目名稱:spring-seed,代碼行數:23,代碼來源:JpaBuilderUtil.java

示例3: entityManagerFactory

import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; //導入依賴的package包/類
@Bean(EntityManagerFactoryBeanName)
@Primary
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
        @Qualifier(DataSourceBeanName) DataSource dataSource,
        @Qualifier(JpaVendorAdapterBeanName) JpaVendorAdapter vendorAdapter) {

    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setDataSource(dataSource);
    entityManagerFactoryBean.setJpaVendorAdapter(vendorAdapter);
    entityManagerFactoryBean.setJpaDialect(new HibernateJpaDialect());
    entityManagerFactoryBean.setPackagesToScan(Organization.class.getPackage().getName());
    entityManagerFactoryBean.setPersistenceUnitName("mysqlsource1");
    entityManagerFactoryBean.afterPropertiesSet();

    return entityManagerFactoryBean;
}
 
開發者ID:omacarena,項目名稱:only-short-poc,代碼行數:17,代碼來源:MySqlSource1Config.java

示例4: entityManagerFactory

import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; //導入依賴的package包/類
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
    DataSource dataSource,
    MultiTenantConnectionProvider multiTenantConnectionProviderImpl,
    CurrentTenantIdentifierResolver currentTenantIdentifierResolverImpl) {
    Map<String, Object> properties = new HashMap<>();
    properties.putAll(jpaProperties.getHibernateProperties(dataSource));
    properties.put(org.hibernate.cfg.Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
    properties
        .put(org.hibernate.cfg.Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProviderImpl);
    properties
        .put(org.hibernate.cfg.Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolverImpl);

    LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(dataSource);
    em.setPackagesToScan(JPA_PACKAGES);
    em.setJpaVendorAdapter(jpaVendorAdapter());
    em.setJpaPropertyMap(properties);
    return em;
}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:21,代碼來源:DatabaseConfiguration.java

示例5: entityManagerFactoryBean

import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; //導入依賴的package包/類
/**
     * EntityManager configuration.
     */
    @Bean(name = "entityManagerFactory")
    public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() {
        final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
        em.setDataSource(getDatasource());
        em.setJpaDialect(jpaDialect());
        em.setPackagesToScan(entityManagerProperties.getPackagesToScan());
        em.setPersistenceUnitName(eclipseLinkProperties.getPersistenceUnitName());
        final DatabasePlatform dp = new MySQLPlatform();
        em.setJpaVendorAdapter(getEclipseLinkJpaVendorAdapter());

        //following code will be used for static weaving. Uncomment when creating war.
		final Map<String, String> propMap = new HashMap<String, String>();
		propMap.put("eclipselink.weaving", eclipseLinkProperties.getWeaving());
		em.setJpaPropertyMap(propMap);

//        em.setLoadTimeWeaver(loadTimeWeaver()); //comment this when using static weaving. Mostly in development environment inside eclipse
        return em;
    }
 
開發者ID:JonkiPro,項目名稱:REST-Web-Services,代碼行數:22,代碼來源:WebDatasourceConfig.java

示例6: entityManagerFactory

import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; //導入依賴的package包/類
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    // JPA settings
    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    // vendorAdapter.setGenerateDdl(true);
    // vendorAdapter.setShowSql(true);
    vendorAdapter.setDatabase(Database.MYSQL);

    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("org.amv.access.model");
    factory.setDataSource(dataSource);
    factory.setJpaProperties(jpaProperties());
    factory.afterPropertiesSet();
    return factory;
}
 
開發者ID:amvnetworks,項目名稱:amv-access-api-poc,代碼行數:17,代碼來源:JpaConfig.java

示例7: entityManagerFactory

import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; //導入依賴的package包/類
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
    EntityManagerFactoryBuilder factoryBuilder)
{
    Map<String, Object> vendorProperties = getVendorProperties();
    customizeVendorProperties(vendorProperties);
    LocalContainerEntityManagerFactoryBean emfb = factoryBuilder.dataSource(getDataSource())
        .packages(getPackagesToScan())
        .persistenceUnit("default")
        .properties(vendorProperties)
        .jta(isJta())
        .build();

    emfb.setPersistenceUnitPostProcessors(new JPosPersistentUnitPostProcessor());
    return emfb;
}
 
開發者ID:vmantek,項目名稱:chimera,代碼行數:17,代碼來源:JPosDatabaseAutoConfiguration.java

示例8: entityManagerFactory

import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; //導入依賴的package包/類
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
    DataSource dataSource,
    MultiTenantConnectionProvider multiTenantConnectionProviderImpl,
    CurrentTenantIdentifierResolver currentTenantIdentifierResolverImpl,
    LocalValidatorFactoryBean localValidatorFactoryBean) {

    Map<String, Object> properties = new HashMap<>();
    properties.putAll(jpaProperties.getHibernateProperties(dataSource));
    properties.put(MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
    properties.put(MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProviderImpl);
    properties.put(MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolverImpl);
    properties.put(JPA_VALIDATION_FACTORY, localValidatorFactoryBean);

    LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(dataSource);
    em.setPackagesToScan(JPA_PACKAGES);
    em.setJpaVendorAdapter(jpaVendorAdapter());
    em.setJpaPropertyMap(properties);
    return em;
}
 
開發者ID:xm-online,項目名稱:xm-ms-balance,代碼行數:22,代碼來源:DatabaseConfiguration.java

示例9: entityManagerFactory

import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; //導入依賴的package包/類
@Bean
public EntityManagerFactory entityManagerFactory() {
    logger.debug("Configuring EntityManager");
    LocalContainerEntityManagerFactoryBean lcemfb = new LocalContainerEntityManagerFactoryBean();
    lcemfb.setPersistenceProvider(new HibernatePersistenceProvider());
    lcemfb.setPersistenceUnitName("persistenceUnit");
    lcemfb.setDataSource(dataSource());
    lcemfb.setJpaDialect(new HibernateJpaDialect());
    lcemfb.setJpaVendorAdapter(jpaVendorAdapter());
    lcemfb.setSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE);
    Properties jpaProperties = new Properties();
    jpaProperties.put("hibernate.generate_statistics", false);
    jpaProperties.put("hibernate.show_sql", Boolean.parseBoolean(databaseShowSQL));
    lcemfb.setJpaProperties(jpaProperties);
    lcemfb.setPackagesToScan("cn.org.once.cstack.model");
    lcemfb.afterPropertiesSet();
    return lcemfb.getObject();
}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:19,代碼來源:DatabaseConfiguration.java

示例10: entityManagerFactory

import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; //導入依賴的package包/類
@Bean
public EntityManagerFactory entityManagerFactory(DataSource dataSource) {
    final Database database = Database.valueOf(vendor.toUpperCase());
    /*
    final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setShowSql(showSql);
    vendorAdapter.setGenerateDdl(showDdl);
    vendorAdapter.setDatabase(database);
    */

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


    return factory.getObject();
}
 
開發者ID:nhsconnect,項目名稱:careconnect-reference-implementation,代碼行數:23,代碼來源:DataSourceConfig.java

示例11: entityManagerFactory

import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; //導入依賴的package包/類
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, MultiTenantConnectionProvider multiTenantConnectionProvider,
                                                                   CurrentTenantIdentifierResolver tenantIdentifierResolver) {
    final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(dataSource);
    em.setPackagesToScan("com.mycompany.models");

    em.setJpaVendorAdapter(this.jpaVendorAdapter());

    final Map<String, Object> jpaProperties = new HashMap<>();
    jpaProperties.put(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
    jpaProperties.put(Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProvider);
    jpaProperties.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, tenantIdentifierResolver);
    jpaProperties.put(Environment.FORMAT_SQL, true);

    em.setJpaPropertyMap(jpaProperties);
    return em;
}
 
開發者ID:SAP,項目名稱:cloud-s4-sdk-examples,代碼行數:19,代碼來源:HibernateConfig.java

示例12: entityManagerFactory

import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; //導入依賴的package包/類
@Bean
public EntityManagerFactory entityManagerFactory() throws SQLException {
	HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
	// vendorAdapter.setGenerateDdl(true); // Crea la tabella e le colonne quando non esistono
	vendorAdapter.setShowSql(config.getShowSql());
	vendorAdapter.setDatabasePlatform("org.hibernate.dialect.MySQL5InnoDBDialect");
	LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
	factory.setJpaVendorAdapter(vendorAdapter);
	List<String> packages = config.getDbEntityPackages();
	packages.add("net.yadaframework.persistence.entity");
	packages.add("net.yadaframework.security.persistence.entity");
	packages.add("net.yadaframework.cms.persistence.entity");
	packages.add("net.yadaframework.commerce.persistence.entity");
	log.info("Scanning packages for entities: {}", StringUtils.join(packages, ","));
	factory.setPackagesToScan(packages.toArray(new String[]{}));
	factory.setDataSource(dataSource());
	factory.afterPropertiesSet();
	return factory.getObject();
}
 
開發者ID:xtianus,項目名稱:yadaframework,代碼行數:20,代碼來源:YadaJpaConfig.java

示例13: entityManagerFactory

import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; //導入依賴的package包/類
@Bean
public FactoryBean<EntityManagerFactory> entityManagerFactory() {
	LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
	emf.setDataSource(dataSource());
	emf.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
	emf.setPackagesToScan(TestJpaDomain.class.getPackage().getName());
	emf.setPersistenceUnitName("test");
	return emf;
}
 
開發者ID:holon-platform,項目名稱:holon-datastore-jpa,代碼行數:10,代碼來源:TestBase.java

示例14: entityManagerFactory

import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; //導入依賴的package包/類
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(dataSource());
    em.setPackagesToScan("com.tickets.business.entities");

    final Properties hibernateProperties = new Properties();
    hibernateProperties.setProperty("hibernate.hbm2ddl.auto", "update");
    hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
    em.setJpaProperties(hibernateProperties);
    
    final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    em.setJpaVendorAdapter(vendorAdapter);

    return em;
}
 
開發者ID:sysuOTS,項目名稱:TicketServer,代碼行數:17,代碼來源:SpringBusinessConfig.java

示例15: entityManagerFactory

import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; //導入依賴的package包/類
/**
 * Big Note: For spring based applications, the difference between different types of the entity manager factory bean is not so much. Spring will
 * always play the role, as container if you configure {@link LocalContainerEntityManagerFactoryBean}  and as application if you configure
 * {@link org.springframework.orm.jpa.LocalEntityManagerFactoryBean}
 *
 * @param dataSource  Factory for connections to the physical data source
 * @param environment Interface representing the environment in which the current application is running.
 * @return suitable entity manager factor bean bean for
 */
@Bean
LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, Environment environment) {
    Properties jpaProperties = new Properties();
    jpaProperties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect"));
    jpaProperties.put("hibernate.hbm2ddl.auto", environment.getRequiredProperty("hibernate.hbm2ddl.auto"));
    jpaProperties.put("hibernate.ejb.naming_strategy", environment.getRequiredProperty("hibernate.ejb.naming_strategy"));
    jpaProperties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql"));
    jpaProperties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql"));
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setDataSource(dataSource);
    entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
    entityManagerFactoryBean.setPackagesToScan("com.logicify.d2g.models");
    entityManagerFactoryBean.setJpaProperties(jpaProperties);
    return entityManagerFactoryBean;
}
 
開發者ID:Logicify,項目名稱:d2g-api,代碼行數:25,代碼來源:RepositoryConfiguration.java


注:本文中的org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。