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

The following examples show how to use org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#getObject() . 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: RepositorySpringConfiguration.java    From personal_book_library_web_project with MIT License 7 votes vote down vote up
@Bean
public EntityManagerFactory entityManagerFactory() throws SQLException {

	HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
	vendorAdapter.setGenerateDdl(true);
	vendorAdapter.setShowSql(true);

	LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
	factory.setJpaVendorAdapter(vendorAdapter);
	factory.setPackagesToScan("com.personal.book.library.datalayer.entity", 
							 "com.personal.book.library.datalayer.repository.jpa");
	factory.setDataSource(dataSource());
	factory.afterPropertiesSet();
	factory.setJpaProperties(jpaProperties());
	
	return factory.getObject();
}
 
Example 2
Source File: JpaCoreConfig.java    From bearchoke with Apache License 2.0 6 votes vote down vote up
@Bean
public EntityManagerFactory entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
    lef.setDataSource(dataSource);
    lef.setJpaVendorAdapter(jpaVendorAdapter());
    String[] packages = environment.getProperty("jpa.packages.to.scan").split(",");
    lef.setPackagesToScan(packages);

    Properties props = new Properties();
    props.put("hibernate.show_sql", "true");
    props.put("hibernate.format_sql", "true");
    props.put("hibernate.ejb.naming_strategy", "org.hibernate.cfg.ImprovedNamingStrategy");
    props.put("hibernate.connection.charSet", "UTF-8");
    props.put("hibernate.current_session_context_class", "jta");
    props.put("hibernate.archive.autodetection", "class");
    props.put("hibernate.transaction.manager_lookup_class", "com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup");
    props.put("hibernate.dialect", environment.getProperty("jpa.dialect"));
    props.put("hibernate.hbm2ddl.auto", environment.getProperty("jpa.hibernate.create.strategy"));
    lef.setJpaProperties(props);

    lef.afterPropertiesSet();

    return lef.getObject();
}
 
Example 3
Source File: OrderConfig.java    From tutorials with MIT License 6 votes vote down vote up
@Bean
public EntityManagerFactory orderEntityManager() {
    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("com.baeldung.atomikos.spring.jpa.order");
    factory.setDataSource(orderDataSource());
    Properties jpaProperties = new Properties();
    //jpaProperties.put("hibernate.show_sql", "true");
    //jpaProperties.put("hibernate.format_sql", "true");
    jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.DerbyDialect");
    jpaProperties.put("hibernate.current_session_context_class", "jta");
    jpaProperties.put("javax.persistence.transactionType", "jta");
    jpaProperties.put("hibernate.transaction.manager_lookup_class", "com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup");
    jpaProperties.put("hibernate.hbm2ddl.auto", "create-drop");
    factory.setJpaProperties(jpaProperties);
    factory.afterPropertiesSet();
    return factory.getObject();
}
 
Example 4
Source File: DataConfiguration.java    From Spring with Apache License 2.0 6 votes vote down vote up
@Bean
public EntityManagerFactory entityManagerFactory(){
    final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setGenerateDdl(true);

    final Properties jpaProperties = new Properties();
    jpaProperties.put("hibernate.hbm2ddl.auto", "create-drop");
    jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");

    final LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setDataSource(dataSource());
    factory.setPackagesToScan("com.oreilly.sdata");
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setJpaProperties(jpaProperties);
    factory.afterPropertiesSet();
    return factory.getObject();
}
 
Example 5
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 6
Source File: EclipseLinkConfig.java    From logging-log4j-audit with Apache License 2.0 6 votes vote down vote up
@Bean
public EntityManagerFactory entityManagerFactory() {
    LOGGER.debug("Creating EclipseLink entity manager.");
    AbstractJpaVendorAdapter vendorAdapter = new EclipseLinkJpaVendorAdapter();
    vendorAdapter.setGenerateDdl(false);
    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    Properties properties = new Properties();
    properties.setProperty("eclipselink.weaving", "static");
    factory.setJpaProperties(properties);
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("org.apache.logging.log4j.catalog");
    factory.setDataSource(dataSourceConfig.dataSource());
    factory.afterPropertiesSet();

    return factory.getObject();
}
 
Example 7
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 8
Source File: EntityManagerFactoryServiceImpl.java    From multitenant with Apache License 2.0 6 votes vote down vote up
@Override
public EntityManagerFactory createTempEntityManagerFactory(
		Organization organization) {
	SingleConnectionDataSource dataSource = dataSourceService.createSingleConnectionDataSource(organization);
	if (dataSource != null) {
		Map<String, Object> vendorProperties = getVendorProperties(dataSource);
		customizeVendorProperties(vendorProperties);
	    Builder builder = getEntityManagerFactoryBuilder(dataSource).dataSource(dataSource).packages(mergePackagesToScan())
				.properties(vendorProperties).jta(isJta());
		LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = builder.build();
		entityManagerFactoryBean.setBeanClassLoader(classLoader);
		entityManagerFactoryBean.setBeanFactory(beanFactory);
		entityManagerFactoryBean.setBeanName(beanName);
		entityManagerFactoryBean.setLoadTimeWeaver(loadTimeWeaver);
		entityManagerFactoryBean.setResourceLoader(resourceLoader);
		entityManagerFactoryBean.afterPropertiesSet();
		return entityManagerFactoryBean.getObject();
	}
	return null;
}
 
Example 9
Source File: DaoConfig.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 10
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 11
Source File: TenancySampleApplication.java    From tenancy-sample with Apache License 2.0 5 votes vote down vote up
public
@Bean
EntityManagerFactory customEntityManagerFactory(DataSource dataSource) {
    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setGenerateDdl(false); // turn off with Discriminator strategy so far!
    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan(TenancySampleApplication.class.getPackage().getName());
    factory.setDataSource(dataSource);
    factory.getJpaPropertyMap().put(Environment.DIALECT, PostgreSQL9Dialect.class.getName());
    factory.getJpaPropertyMap().put(Environment.MULTI_TENANT, MultiTenancyStrategy.DISCRIMINATOR);
    factory.getJpaPropertyMap().put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, new TenantHolder());
    factory.afterPropertiesSet();
    return factory.getObject();
}
 
Example 12
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 13
Source File: HibernateConfig.java    From logging-log4j-audit with Apache License 2.0 5 votes vote down vote up
@Bean
public EntityManagerFactory entityManagerFactory() {
    AbstractJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setGenerateDdl(false);

    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("org.apache.logging.log4j.catalog");
    factory.setDataSource(dataSourceConfig.dataSource());
    factory.afterPropertiesSet();

    return factory.getObject();
}
 
Example 14
Source File: Application.java    From blog-examples with Apache License 2.0 5 votes vote down vote up
@Bean
public EntityManagerFactory entityManagerFactory() throws SQLException {
	HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
	vendorAdapter.setGenerateDdl(true);
	LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
	factory.setJpaVendorAdapter(vendorAdapter);
	factory.setPackagesToScan("com.mscharhag.springjooq.entity");
	factory.setDataSource(dataSource());
	factory.afterPropertiesSet();
	return factory.getObject();
}
 
Example 15
Source File: TestConfiguration.java    From jwala with Apache License 2.0 4 votes vote down vote up
@Bean
public PlatformTransactionManager getTransactionManager(LocalContainerEntityManagerFactoryBean factoryBean) {
    return new JpaTransactionManager(factoryBean.getObject());
}
 
Example 16
Source File: JpaConfig.java    From spring-reactive-sample with GNU General Public License v3.0 4 votes vote down vote up
@Bean
public PlatformTransactionManager transactionManager(LocalContainerEntityManagerFactoryBean entityManagerFactory) {
    return new JpaTransactionManager(entityManagerFactory.getObject());
}
 
Example 17
Source File: MemberDataSourceConfiguration.java    From sfg-blog-posts with GNU General Public License v3.0 4 votes vote down vote up
@Primary
@Bean
public PlatformTransactionManager memberTransactionManager(
        final @Qualifier("memberEntityManagerFactory") LocalContainerEntityManagerFactoryBean memberEntityManagerFactory) {
    return new JpaTransactionManager(memberEntityManagerFactory.getObject());
}
 
Example 18
Source File: PersistenceImpl.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Inject
@Named("entityManagerFactory")
public void setFactory(LocalContainerEntityManagerFactoryBean factoryBean) {
    this.jpaEmf = factoryBean.getObject();
}
 
Example 19
Source File: CardDataSourceConfiguration.java    From sfg-blog-posts with GNU General Public License v3.0 4 votes vote down vote up
@Bean
public PlatformTransactionManager cardTransactionManager(
        final @Qualifier("cardEntityManagerFactory") LocalContainerEntityManagerFactoryBean cardEntityManagerFactory) {
    return new JpaTransactionManager(cardEntityManagerFactory.getObject());
}
 
Example 20
Source File: MultiTenancyJpaConfiguration.java    From multitenancy with Apache License 2.0 2 votes vote down vote up
/**
 * Interface used to interact with the entity manager factory for the
 * persistence unit.
 * 
 * @param entityManagerFactoryBean
 * @return
 */
@Bean
public EntityManagerFactory entityManagerFactory(LocalContainerEntityManagerFactoryBean entityManagerFactoryBean) {
    return entityManagerFactoryBean.getObject();
}