List of usage examples for org.springframework.orm.jpa LocalContainerEntityManagerFactoryBean afterPropertiesSet
@Override public void afterPropertiesSet() throws PersistenceException
From source file:com.qpark.eip.core.spring.lockedoperation.config.EipLockedoperationConfig.java
/** * Get the {@link LocalContainerEntityManagerFactoryBean}. * * @return the {@link LocalContainerEntityManagerFactoryBean}. *///from w w w . j a v a2s . com @Bean(name = ENTITY_MANAGER_FACTORY_NAME) public EntityManagerFactory getEntityManagerFactory() { AbstractJpaVendorAdapter jpaVendorAdapter = this.getJpaVendorAdapter(); if (jpaVendorAdapter == null) { throw new RuntimeException(String.format("%s jpaVendorAdpater not set properly %s.", ENTITY_MANAGER_FACTORY_NAME, String.valueOf(jpaVendorAdapter))); } String jpaVendorAdapterDatabasePlatform = this.jpaVendorAdapterConfiguration .getJpaVendorAdpaterDatabasePlatform(); if (jpaVendorAdapterDatabasePlatform == null || jpaVendorAdapterDatabasePlatform.trim().length() == 0) { throw new RuntimeException(String.format("%s jpaVendorAdpaterDatabasePlatform not set properly %s.", ENTITY_MANAGER_FACTORY_NAME, String.valueOf(jpaVendorAdapterDatabasePlatform))); } LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean(); bean.setPersistenceXmlLocation(new StringBuffer(96).append("classpath:/META-INF/") .append(PERSISTENCE_UNIT_NAME).append("/persistence.xml").toString()); bean.setPersistenceUnitName(PERSISTENCE_UNIT_NAME); bean.setDataSource(this.datasource); jpaVendorAdapter.setDatabasePlatform(jpaVendorAdapterDatabasePlatform); jpaVendorAdapter.setShowSql(false); if (this.isJpaVendorAdapterGenerateDdl()) { jpaVendorAdapter.setGenerateDdl(true); if (HibernateJpaVendorAdapter.class.isInstance(jpaVendorAdapter)) { bean.getJpaPropertyMap().put("hibernate.hbm2ddl.auto", "update"); } } else { jpaVendorAdapter.setGenerateDdl(false); } bean.setJpaVendorAdapter(jpaVendorAdapter); bean.afterPropertiesSet(); return bean.getObject(); }
From source file:org.drugis.addis.config.MainConfig.java
@Bean(name = "emAddisCore") public LocalContainerEntityManagerFactoryBean entityManagerFactory() { HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); vendorAdapter.setGenerateDdl(false); vendorAdapter.setShowSql(false);// w w w. j ava 2 s . c o m LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); em.setJpaProperties(additionalProperties()); em.setJpaVendorAdapter(vendorAdapter); em.setPackagesToScan("org.drugis.addis.projects", "org.drugis.addis.outcomes", "org.drugis.addis.interventions", "org.drugis.addis.security", "org.drugis.addis.analyses", "org.drugis.addis.scenarios", "org.drugis.addis.models", "org.drugis.addis.problems", "org.drugis.addis.covariates", "org.drugis.trialverse", "org.drugis.addis.scaledUnits", "org.drugis.addis.subProblems", "org.drugis.addis.ordering", "org.drugis.addis.workspaceSettings"); em.setDataSource(dataSource()); em.setPersistenceUnitName("addisCore"); em.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver()); em.afterPropertiesSet(); return em; }
From source file:fr.paris.lutece.portal.service.jpa.JPAStartupService.java
/** * Initialize JPA objects (Datasource, Persistence Unit Manager, Entity Manager Factory, * Transaction Manager) for each pool./* w w w. j a va 2s.com*/ */ public void process() { ReferenceList list = new ReferenceList(); AppConnectionService.getPoolList(list); Map<String, EntityManagerFactory> mapFactories = new HashMap<String, EntityManagerFactory>(); List<PlatformTransactionManager> listTransactionManagers = new ArrayList<PlatformTransactionManager>(); _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 = (JpaDialect) SpringContextService.getBean("jpaDialect"); lcemfb.setJpaDialect(jpaDialect); Map mapJpaProperties = (Map) 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 = (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 = (EntityManagerService) SpringContextService.getBean("entityManagerService"); ems.setMapFactories(mapFactories); ChainedTransactionManager ctm = (ChainedTransactionManager) SpringContextService .getBean("transactionManager"); ctm.setTransactionManagers(listTransactionManagers); _log.info("JPA Startup Service : completed successfully"); }
From source file:gt.dakaik.config.RootContext.java
@Bean public EntityManagerFactory entityManagerFactory() throws ClassNotFoundException { LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); entityManagerFactoryBean.setDataSource(dataSource()); entityManagerFactoryBean/*from w ww.j a v a 2 s .c o m*/ .setPackagesToScan(environment.getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN)); entityManagerFactoryBean.setPersistenceProvider(new HibernatePersistenceProvider()); entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); Properties jpaProterties = new Properties(); jpaProterties.put(PROPERTY_NAME_HIBERNATE_DIALECT, environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_DIALECT)); jpaProterties.put(PROPERTY_NAME_HIBERNATE_FORMAT_SQL, environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_FORMAT_SQL)); jpaProterties.put(PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY, environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY)); jpaProterties.put(PROPERTY_NAME_HIBERNATE_SHOW_SQL, environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_SHOW_SQL)); jpaProterties.put(PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO, environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO)); entityManagerFactoryBean.setJpaProperties(jpaProterties); entityManagerFactoryBean.afterPropertiesSet(); return entityManagerFactoryBean.getObject(); }
From source file:cz.lbenda.coursing.client.ClientAppConfig.java
public @Bean EntityManagerFactory entityManagerFactory() { try {/*from w w w.ja va2 s . c o m*/ EclipseLinkJpaVendorAdapter vendorAdapter = new EclipseLinkJpaVendorAdapter(); vendorAdapter.setDatabasePlatform("org.eclipse.persistence.platform.database.H2Platform"); vendorAdapter.setShowSql(true); vendorAdapter.setGenerateDdl(true); EclipseLinkJpaDialect dialect = new EclipseLinkJpaDialect(); dialect.setLazyDatabaseTransaction(true); LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); factory.setJpaVendorAdapter(vendorAdapter); factory.setJpaDialect(dialect); factory.setPackagesToScan("cz.lbenda.coursing"); factory.setDataSource(dataSource()); factory.setPersistenceXmlLocation("classpath*:META-INF/persistence.xml"); factory.setPersistenceUnitName("coursing"); /* Map<String, String> prop = new HashMap<>(); prop.put("eclipselink.deploy-on-startup", "true"); prop.put("eclipselink.ddl-generation", "create-or-extend-tables"); prop.put("eclipselink.ddl-generation.output-mode", "database"); prop.put("eclipselink.create-ddl-jdbc-file-name", "create.sql"); prop.put("eclipselink.weaving", "static"); prop.put("eclipselink.weaving.lazy", "true"); prop.put("eclipselink.weaving.internal", "true"); prop.put("eclipselink.logging.level", "SEVERE"); prop.put("eclipselink.query-results-cache.type", "WEAK"); prop.put("eclipselink.jdbc.batch-writing", "JDBC"); prop.put("eclipselink.jdbc.batch-writing.size", "1000"); factory.setJpaPropertyMap(prop); */ // factory.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver()); factory.afterPropertiesSet(); return factory.getObject(); } catch (Exception e) { LOG.trace("Faild create entityManagerFactory", e); throw new RuntimeException("Faild create entityManagerFactory", e); } }
From source file:au.com.shawware.sandbox.persistence.JPAConfiguration.java
/** * Defines the entity manager factory to use. * /*from w ww . j a v a 2 s. c o m*/ * @return the entity manager factory bean * * @throws SQLException error creating the bean */ @Bean public EntityManagerFactory entityManagerFactory() throws SQLException { final HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter(); adapter.setShowSql(true); adapter.setGenerateDdl(true); // adapter.setDatabase(Database.HSQL); final LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); factory.setJpaVendorAdapter(adapter); factory.setPackagesToScan(Node.class.getPackage().getName()); factory.setDataSource(dataSource()); final Properties jpaProperties = new Properties(); jpaProperties.setProperty("hibernate.show_sql", "true"); // redundant? jpaProperties.setProperty("hibernate.format_sql", "true"); jpaProperties.setProperty("hibernate.hbm2ddl.auto", "create"); jpaProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"); jpaProperties.setProperty("hibernate.connection.pool_size", "0"); // jpaProperties.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver"); // jpaProperties.setProperty("hibernate.hibernate.transaction.factory_class", "org.hibernate.transaction.JDBCTransactionFactory"); jpaProperties.setProperty("hibernate.connection.url", "jdbc:hsqldb:file:target/data/test;shutdown=true"); jpaProperties.setProperty("hibernate.connection.username", "sa"); jpaProperties.setProperty("hibernate.connection.password", ""); jpaProperties.setProperty("hibernate.connection.autocommit", "true"); jpaProperties.setProperty("hibernate.jdbc.batch_size", "0"); jpaProperties.setProperty("hibernate.ejb.entitymanager_factory_name", "sandbox"); factory.setJpaProperties(jpaProperties); // The following method call is important. Things break without it. factory.afterPropertiesSet(); return factory.getObject(); }
From source file:org.unitils.orm.jpa.util.JpaEntityManagerFactoryLoader.java
/** * @param testObject The test instance, not null * @param jpaConfig The configuration parameters for the <code>EntityManagerFactory</code> * @return A completely configured <code>AbstractEntityManagerFactoryBean</code> *///from ww w. j a v a2s . co m protected AbstractEntityManagerFactoryBean createEntityManagerFactoryBean(Object testObject, JpaConfig jpaConfig) { LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean(); factoryBean.setDataSource(getDataSource()); factoryBean.setJpaVendorAdapter(getJpaProviderSupport().getSpringJpaVendorAdaptor()); String persistenceXmlFile = jpaConfig.getConfigFiles().iterator().next(); if (!StringUtils.isEmpty(persistenceXmlFile)) { factoryBean.setPersistenceXmlLocation(persistenceXmlFile); } factoryBean.setPersistenceUnitName(jpaConfig.getPersistenceUnitName()); LoadTimeWeaver loadTimeWeaver = getJpaProviderSupport().getLoadTimeWeaver(); if (loadTimeWeaver != null) { factoryBean.setLoadTimeWeaver(loadTimeWeaver); } if (jpaConfig.getConfigMethod() != null) { try { ReflectionUtils.invokeMethod(testObject, jpaConfig.getConfigMethod(), factoryBean); } catch (InvocationTargetException e) { throw new UnitilsException("Error while invoking custom config method", e.getCause()); } } factoryBean.afterPropertiesSet(); return factoryBean; }