本文整理汇总了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();
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}