@Bean() public LocalContainerEntityManagerFactoryBean entityManagerFactory() { LocalContainerEntityManagerFactoryBean retVal = new LocalContainerEntityManagerFactoryBean(); retVal.setPersistenceUnitName("HAPI_PU"); retVal.setDataSource(dataSource()); retVal.setPackagesToScan("ca.uhn.fhir.jpa.entity"); retVal.setPersistenceProvider(new HibernatePersistenceProvider()); retVal.setJpaProperties(jpaProperties()); retVal.afterPropertiesSet(); return retVal; }
@Bean(name = "entityManagerFactory") public LocalContainerEntityManagerFactoryBean emf() throws IOException { Properties jpaProps = new Properties(); jpaProps.load(AppConfig.class.getClassLoader().getResourceAsStream("jpa.properties")); LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean(); emf.setDataSource(dataSource()); emf.setJpaVendorAdapter(jpaVendorAdapter()); emf.setPackagesToScan("com.beam.sample.model.jpa"); emf.setJpaProperties(jpaProps); emf.setPersistenceProvider(persistenceProvider()); return emf; }
@Bean @ConfigurationProperties(prefix = "spring.jpa") public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) { LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean(); emf.setPackagesToScan("app.models"); emf.setPersistenceProvider(new HibernatePersistenceProvider()); Properties jpaProperties = new Properties(); // todo:����ǰȡ������ // jpaProperties.setProperty("hibernate.hbm2ddl.auto", "create"); jpaProperties.setProperty("hibernate.hbm2ddl.auto", "update"); jpaProperties.setProperty("hibernate.show_sql", "false"); jpaProperties.setProperty("hibernate.format_sql", "false"); jpaProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5InnoDBDialect"); emf.setJpaProperties(jpaProperties); emf.setDataSource(dataSource); return emf; }