List of usage examples for org.springframework.orm.jpa LocalContainerEntityManagerFactoryBean LocalContainerEntityManagerFactoryBean
LocalContainerEntityManagerFactoryBean
From source file:org.springsource.html5expenses.config.ServicesConfiguration.java
@Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws Exception { HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter(); jpaVendorAdapter.setGenerateDdl(true); jpaVendorAdapter.setShowSql(true);/*from w w w . java 2 s .com*/ List<String> pkgs = Arrays.asList(Charge.class.getPackage().getName(), ManagedFile.class.getPackage().getName(), Expense.class.getPackage().getName()); Map<String, String> mapOfJpaProperties = new HashMap<String, String>(); mapOfJpaProperties.put("hibernate.hbm2ddl.auto", "create"); LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); localContainerEntityManagerFactoryBean.setJpaVendorAdapter(jpaVendorAdapter); localContainerEntityManagerFactoryBean.setJpaPropertyMap(mapOfJpaProperties); localContainerEntityManagerFactoryBean.setDataSource(dataSource()); localContainerEntityManagerFactoryBean.setPackagesToScan(pkgs.toArray(new String[pkgs.size()])); // look ma, no persistence.xml ! return localContainerEntityManagerFactoryBean; }
From source file:org.apigw.monitoring.config.PersistenceConfig.java
@Bean @DependsOn("flyway") public LocalContainerEntityManagerFactoryBean entityManagerFactory() { log.debug("Setting up entityManagerFactory"); LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); vendorAdapter.setShowSql(Boolean.getBoolean(hibernateShowSql)); vendorAdapter.setDatabasePlatform("org.hibernate.dialect." + hibernateDialect); factory.setDataSource(dataSource()); factory.setJpaVendorAdapter(vendorAdapter); factory.setPackagesToScan("org.apigw.monitoring.types.domain"); Properties jpaProperties = new Properties(); factory.setJpaProperties(jpaProperties); factory.afterPropertiesSet();/* w ww. j a v a 2 s . c o m*/ factory.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver()); return factory; }
From source file:com.gopivotal.cla.repository.RepositoryConfiguration.java
@Bean EntityManagerFactory entityManagerFactory() { HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); factory.setJpaVendorAdapter(vendorAdapter); factory.setDataSource(dataSource()); factory.afterPropertiesSet();//from w ww . j a v a 2s. c om return factory.getObject(); }
From source file:com.oasisdigital.sdre.ApplicationConfig.java
/** * Sets up a {@link LocalContainerEntityManagerFactoryBean} to use Hibernate. Activates picking up entities from the * project's base package.//from ww w . j a v a 2 s.c om * * @return */ @Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() { HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); vendorAdapter.setDatabase(Database.HSQL); vendorAdapter.setGenerateDdl(true); LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); factory.setJpaVendorAdapter(vendorAdapter); factory.setPackagesToScan(getClass().getPackage().getName()); factory.setDataSource(dataSource()); return factory; }
From source file:me.bulat.jivr.webmin.config.DataAppConfig.java
@Profile("default") @Bean(name = "userEntityManagerFactory") public LocalContainerEntityManagerFactoryBean configureEntityManagerFactory() { LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); entityManagerFactoryBean.setDataSource(dataSource()); entityManagerFactoryBean.setPackagesToScan("me.bulat.jivr.webmin.data.*"); entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); Properties jpaProperties = new Properties(); jpaProperties.put(org.hibernate.cfg.Environment.DIALECT, dialect); jpaProperties.put(org.hibernate.cfg.Environment.HBM2DDL_AUTO, hbm2ddlAuto); jpaProperties.put(Environment.SHOW_SQL, showSql); entityManagerFactoryBean.setJpaProperties(jpaProperties); return entityManagerFactoryBean; }
From source file:com.controller.config.DAOConfig.java
@Bean public LocalContainerEntityManagerFactoryBean getEntityManagerFactoryBean() { LocalContainerEntityManagerFactoryBean lBean = new LocalContainerEntityManagerFactoryBean(); lBean.setDataSource(dataSource());//ww w . jav a 2 s . c o m lBean.setPersistenceProviderClass(org.datanucleus.api.jpa.PersistenceProviderImpl.class); lBean.setPackagesToScan(new String[] { "com.controller.dao.impl.spring" }); lBean.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver()); Properties japProperties = new Properties(); japProperties.put("javax.persistence.jdbc.driver", mEnvironment.getProperty("DATABASE_DRIVER_NAME")); lBean.setJpaProperties(japProperties); lBean.afterPropertiesSet(); return lBean; }
From source file:id.ac.ipb.ilkom.training.ApplicationConfiguration.java
@Bean LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) { LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); entityManagerFactoryBean.setDataSource(dataSource); entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); entityManagerFactoryBean.setPackagesToScan("id.ac.ipb.ilkom.training"); Properties jpaProperties = new Properties(); //Configures the used database dialect. This allows Hibernate to create SQL //that is optimized for the used database. jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); //Specifies the action that is invoked to the database when the Hibernate //SessionFactory is created or closed. jpaProperties.put("hibernate.hbm2ddl.auto", "update"); //If the value of this property is true, Hibernate writes all SQL //statements to the console. jpaProperties.put("hibernate.show_sql", "true"); //If the value of this property is true, Hibernate will format the SQL //that is written to the console. jpaProperties.put("hibernate.format_sql", "true"); entityManagerFactoryBean.setJpaProperties(jpaProperties); return entityManagerFactoryBean; }
From source file:com.googlecode.jeeunit.example.test.spring.SpringTestConfig.java
/** * This bean is not the EntityManagerFactory itself, but a Spring factory for JPA * EntityManagerFactories. The actual EntityManagerFactory can be obtained by invoking * <code>getObject()</code>. * <p>/*from w ww .j a v a 2s . c om*/ * The Spring factory lets us override settings from the default <code>persistence.xml</code>. * In particular, in the test environment we cannot access the data source via JNDI, and there * is no JTA transaction manager. This is why we have to use an alternative * <code>test-persistence.xml</code>. * <p> * TODO: It would be nice to avoid the <code>test-persistence.xml</code> and to provide all the * required overrides in this bean. * * @return */ @Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() { LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean(); bean.setDataSource(dataSource()); bean.setPersistenceProvider(new HibernatePersistence()); bean.setPersistenceXmlLocation("classpath:META-INF/test-persistence.xml"); return bean; }
From source file:com.dominion.salud.nomenclator.configuration.NOMENCLATORJpaConfiguration.java
@Bean @Autowired/*from www.j ava 2 s . c o m*/ public EntityManagerFactory entityManagerFactory() { logger.info("INICIANDO EL MODULO"); HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter(); adapter.setGenerateDdl(Boolean.getBoolean(environment.getRequiredProperty("hibernate.generate_ddl"))); adapter.setShowSql(Boolean.getBoolean(environment.getRequiredProperty("hibernate.show_sql"))); adapter.setDatabasePlatform(environment.getRequiredProperty("hibernate.dialect")); logger.info(" Iniciando conexion a base de datos"); LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); factory.setDataSource(dataSource()); factory.setJpaVendorAdapter(adapter); factory.setPackagesToScan("com.dominion.salud.nomenclator.negocio.entities"); factory.afterPropertiesSet(); factory.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver()); logger.info(" Conexion a base de datos iniciada correctamente"); return factory.getObject(); }
From source file:se.uu.it.cs.recsys.persistence.config.PersistenceSpringConfig.java
@Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() { LocalContainerEntityManagerFactoryBean lemfb = new LocalContainerEntityManagerFactoryBean(); lemfb.setDataSource(dataSource());/* ww w. j a v a 2 s.c o m*/ lemfb.setJpaVendorAdapter(jpaVendorAdapter()); lemfb.setPackagesToScan("se.uu.it.cs.recsys.persistence.entity"); return lemfb; }