@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; }
@Bean @ConditionalOnMissingBean public EntityManagerFactoryBuilder entityManagerFactoryBuilder( JpaVendorAdapter jpaVendorAdapter, ObjectProvider<PersistenceUnitManager> persistenceUnitManagerProvider) { EntityManagerFactoryBuilder builder = new EntityManagerFactoryBuilder( jpaVendorAdapter, this.properties.getProperties(), persistenceUnitManagerProvider.getIfAvailable()); builder.setCallback(getVendorCallback()); return builder; }
/** * Create a {@Link LocalContainerEntityManagerFactoryBean} for the workflow datasource. */ @Bean @WorkflowPersistenceUnit public LocalContainerEntityManagerFactoryBean workflowEntityManagerFactory( EntityManagerFactoryBuilder builder, @WorkflowPersistenceUnit DataSource workflowDatasource) { LocalContainerEntityManagerFactoryBean factoryBean = builder .dataSource(workflowDatasource) .packages((String[]) null) .persistenceUnit(Constants.PERSISTENCE_UNIT_NAME) .jta(true) .build(); // JBPM needs them factoryBean.getJpaPropertyMap().put("hibernate.max_fetch_depth", "3"); factoryBean.getJpaPropertyMap().put("hibernate.id.new_generator_mappings", "false"); return factoryBean; }
@Primary @Bean(name = "oneEntityManagerFactory") public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder) { DataSource dataSource = dataSource(); return builder.dataSource(dataSource).packages("com.easynetcn.cloud.one.web.data.entity") .persistenceUnit("onePersistenceUnit").build(); }
@Bean(name = "entityManagerFactoryUser") public LocalContainerEntityManagerFactoryBean entityManagerFactoryUser (EntityManagerFactoryBuilder builder) { return builder .dataSource(userDataSource) .properties(getVendorProperties(userDataSource)) .packages(new String[]{ "com.myspringboot.repository.user", "com.myspringboot.entity" }) //设置应用userDataSource的基础包名 .persistenceUnit("userPersistenceUnit") .build(); }
@Primary @Bean(name = "entityManagerFactoryBook") public LocalContainerEntityManagerFactoryBean entityManagerFactoryBook (EntityManagerFactoryBuilder builder) { return builder .dataSource(bookDataSource) .properties(getVendorProperties(bookDataSource)) .packages(new String[]{"com.myspringboot.repository.book", "com.myspringboot.entity"}) //设置应用bookDataSource的基础包名 .persistenceUnit("bookPersistenceUnit") .build(); }
@Bean(name = "entityManagerFactory") public LocalContainerEntityManagerFactoryBean entityManagerFactory( EntityManagerFactoryBuilder factory) { return factory.dataSource(dataSource()) .packages("com.nixmash.blog.jpa") .properties(getVendorProperties(dataSource())) .build(); }
/** * 实体管理对象 * @param builder 由spring注入这个对象,首先根据type注入(多个就取声明@Primary的对象),否则根据name注入 * @return */ @Bean @Primary public LocalContainerEntityManagerFactoryBean firstEntityManagerFactory( EntityManagerFactoryBuilder builder) { return builder .dataSource(firstDataSource()) .packages("com.jwcq.entity") .persistenceUnit("firstDs") .build(); }
/** * 实体管理对象 * @param builder 由spring注入这个对象,首先根据type注入(多个就取声明@Primary的对象),否则根据name注入 * @return */ @Bean(name = "secondEntityManagerFactory") public LocalContainerEntityManagerFactoryBean secondEntityManagerFactory( EntityManagerFactoryBuilder builder) { return builder .dataSource(secondDataSource()) .packages("com.jwcq.user.entity") .persistenceUnit("secondDs") .build(); }
/** * EntityManagerFactory类似于Hibernate的SessionFactory,mybatis的SqlSessionFactory * 总之,在执行操作之前,我们总要获取一个EntityManager,这就类似于Hibernate的Session, * mybatis的sqlSession. * @return */ @Bean(name = "readEntityManagerFactoryBean") public LocalContainerEntityManagerFactoryBean readEntityManagerFactoryBean(EntityManagerFactoryBuilder builder) { return builder .dataSource(readDruidDataSource) .properties(jpaProperties.getProperties()) .packages("com.lc.springBoot.jpa.entity") //设置实体类所在位置 .persistenceUnit("readPersistenceUnit")//持久化单元名称 .build(); //.getObject(); }
/** * 我们通过LocalContainerEntityManagerFactoryBean来获取EntityManagerFactory实例 * @return */ @Bean(name = "writeEntityManagerFactoryBean") @Primary public LocalContainerEntityManagerFactoryBean writeEntityManagerFactoryBean(EntityManagerFactoryBuilder builder) { return builder .dataSource(writeDruidDataSource) .properties(jpaProperties.getProperties()) .packages("com.lc.springBoot.jpa.entity") //设置实体类所在位置 .persistenceUnit("writePersistenceUnit") .build(); //.getObject();//不要在这里直接获取EntityManagerFactory }
@Bean(name = "secondaryEntityManager") public LocalContainerEntityManagerFactoryBean secondaryEntityManagerFactoryBean(EntityManagerFactoryBuilder builder) { return builder .dataSource(secondaryDataSource()) .properties(hibernateProperties()) .packages("com.xiaofeng.domain") //设置实体类所在位置 .persistenceUnit("secondaryPersistenceUnit") .build(); }
@Primary @Bean(name = "primaryEntityManager") public LocalContainerEntityManagerFactoryBean primaryEntityManagerFactoryBean(EntityManagerFactoryBuilder builder) { return builder .dataSource(primaryDataSource()) .properties((hibernateProperties())) .packages("com.xiaofeng.domain") //设置实体类所在位置 .persistenceUnit("primaryPersistenceUnit") .build(); }
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean(String name, final DataSource dataSource) { EntityManagerFactoryBuilder emfBuilder = new EntityManagerFactoryBuilder( vendorAdapter(), getProperties(), null); Builder builder = emfBuilder .dataSource(dataSource) .persistenceUnit(name) .properties(getHibernateProperties(dataSource)) .jta(false); if (ArrayUtils.isNotEmpty(annotatedClasses)) { builder.packages(annotatedClasses); } else { builder.packages(packageToScan); } return builder.build(); }
@Bean @Primary @ConditionalOnMissingBean({ LocalContainerEntityManagerFactoryBean.class, EntityManagerFactory.class }) public LocalContainerEntityManagerFactoryBean entityManagerFactory( EntityManagerFactoryBuilder factoryBuilder) { Map<String, Object> vendorProperties = getVendorProperties(); customizeVendorProperties(vendorProperties); return factoryBuilder.dataSource(this.dataSource).packages(getPackagesToScan()) .properties(vendorProperties).jta(isJta()).build(); }
@Bean public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() { Map<String, Object> properties = new HashMap<String, Object>(); properties.put("configured", "manually"); properties.put("hibernate.transaction.jta.platform", NoJtaPlatform.INSTANCE); return new EntityManagerFactoryBuilder(new HibernateJpaVendorAdapter(), properties, null).dataSource(this.dataSource).build(); }
@Bean(name = SECONDARY_ENTITY_MANAGER_FACTORY) public LocalContainerEntityManagerFactoryBean secondaryEntityManagerFactory(EntityManagerFactoryBuilder builder) { return builder .dataSource(secondaryDataSource()) .packages("demo.model.secondary") .persistenceUnit(SECONDARY_PERSISTENCE_UNIT) .properties(secondaryJpaProperties().getHibernateProperties(secondaryDataSource())) .build(); }
@Bean(name = PRIMARY_ENTITY_MANAGER_FACTORY) @Primary public LocalContainerEntityManagerFactoryBean primaryEntityManagerFactory(EntityManagerFactoryBuilder builder) { return builder .dataSource(primaryDataSource()) .packages("demo.model.primary") .persistenceUnit(PRIMARY_PERSISTENCE_UNIT) .properties(primaryJpaProperties().getHibernateProperties(primaryDataSource())) .build(); }
@Bean @ConditionalOnMissingBean public EntityManagerFactoryBuilder entityManagerFactoryBuilder( JpaVendorAdapter jpaVendorAdapter) { EntityManagerFactoryBuilder builder = new EntityManagerFactoryBuilder( jpaVendorAdapter, this.jpaProperties.getProperties(), this.persistenceUnitManager); builder.setCallback(getVendorCallback()); return builder; }
@Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory( EntityManagerFactoryBuilder factoryBuilder, DataSource dataSource) { Map<String, String> hibernateProperties = mapPropertyNames("hibernate", hibernateConfiguration()); return factoryBuilder.dataSource(dataSource).packages( "com.pungwe.cms.jpa.entity", "com.pungwe.cms.jpa.module", "com.pungwe.cms.jpa.theme", "com.pungwe.cms.jpa.block", "com.pungwe.cms.jpa.menu", "com.pungwe.cms.jpa.security" ).properties(hibernateProperties).build(); }
/** * Create a {@Link LocalContainerEntityManagerFactoryBean} for the orchestrator datasource. */ @Bean @Primary @OrchestratorPersistenceUnit public LocalContainerEntityManagerFactoryBean entityManagerFactory( EntityManagerFactoryBuilder builder, @OrchestratorPersistenceUnit DataSource datasource) { return builder .dataSource(datasource) .persistenceUnit("orchestrator") .packages("it.reply.orchestrator.dal.entity") .jta(true) .build(); }
@Primary @Bean public EntityManager entityManager(EntityManagerFactoryBuilder builder) { return entityManagerFactory(builder).getObject().createEntityManager(); }
@Primary @Bean(name = "oneTransactionManager") public PlatformTransactionManager transactionManagerPrimary(EntityManagerFactoryBuilder builder) { return new JpaTransactionManager(entityManagerFactory(builder).getObject()); }
@Bean(name = "entityManagerUser") public EntityManager entityManager(EntityManagerFactoryBuilder builder) { return entityManagerFactoryUser(builder).getObject().createEntityManager(); }
@Bean(name = "transactionManagerUser") public PlatformTransactionManager transactionManagerUser(EntityManagerFactoryBuilder builder) { return new JpaTransactionManager(entityManagerFactoryUser(builder).getObject()); }
@Primary @Bean(name = "entityManagerBook") public EntityManager entityManager(EntityManagerFactoryBuilder builder) { return entityManagerFactoryBook(builder).getObject().createEntityManager(); }
@Primary @Bean(name = "transactionManagerBook") public PlatformTransactionManager transactionManagerBook(EntityManagerFactoryBuilder builder) { return new JpaTransactionManager(entityManagerFactoryBook(builder).getObject()); }
/** * 配置事物管理器 * @return */ @Bean(name = "readTransactionManager") public PlatformTransactionManager readTransactionManager(EntityManagerFactoryBuilder builder) { return new JpaTransactionManager(readEntityManagerFactory(builder)); }
/** * 配置事物管理器 * @return */ @Bean(name = "writeTransactionManager") @Primary public PlatformTransactionManager writeTransactionManager(EntityManagerFactoryBuilder builder) { return new JpaTransactionManager(writeEntityManagerFactory(builder)); }
@Bean(name = "commonEntityManagerFactory") public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder) { return builder.dataSource(dataSource).properties(jpaProperties.getHibernateProperties(dataSource)).packages("com.zhaoql.customer.domain.entity").build(); }
@Bean(name = "commonEntityManagerFactory") public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder) { return builder.dataSource(dataSource).properties(jpaProperties.getHibernateProperties(dataSource)).packages("com.zhaoql.product.domain.entity").build(); }
@Bean(name = "commonEntityManagerFactory") public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder) { return builder.dataSource(dataSource).properties(jpaProperties.getHibernateProperties(dataSource)).packages("com.zhaoql.order.domain.entity").build(); }
@Bean(name = "entityManagerFactoryPrimary") public LocalContainerEntityManagerFactoryBean entityManagerFactoryCreate(EntityManagerFactoryBuilder builder) { return builder.dataSource(primaryDataSource).properties(getVendorProperties(primaryDataSource)) .packages("org.gra4j.dataMigration.crud.entity") // 设置实体类所在位置 .persistenceUnit("primaryPersistenceUnit").build(); }