Package org.springframework.orm.jpa

Examples of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean


  @Test
  public void customPersistenceUnitManager() throws Exception {
    setupTestConfiguration(TestConfigurationWithCustomPersistenceUnitManager.class);
    this.context.refresh();
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = this.context
        .getBean(LocalContainerEntityManagerFactoryBean.class);
    Field field = LocalContainerEntityManagerFactoryBean.class
        .getDeclaredField("persistenceUnitManager");
    field.setAccessible(true);
    assertThat(field.get(entityManagerFactoryBean),
View Full Code Here


    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactory(
        DataSource dataSource, JpaVendorAdapter adapter) {

      LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
      factoryBean.setJpaVendorAdapter(adapter);
      factoryBean.setDataSource(dataSource);
      factoryBean.setPersistenceUnitName("manually-configured");
      Map<String, Object> properties = new HashMap<String, Object>();
      properties.put("configured", "manually");
      properties.put("hibernate.transaction.jta.platform", NoJtaPlatform.INSTANCE);
      factoryBean.setJpaPropertyMap(properties);
      return factoryBean;
    }
View Full Code Here

  @Test
  public void entityManagerFactoryPropertiesNotOverwritingDefaults() {
    EntityManagerFactoryBuilder factory = new EntityManagerFactoryBuilder(
        new HibernateJpaVendorAdapter(), this.properties, null);
    LocalContainerEntityManagerFactoryBean result1 = factory
        .dataSource(this.dataSource1)
        .properties(Collections.singletonMap("foo", "spam")).build();
    assertFalse(result1.getJpaPropertyMap().isEmpty());
    assertTrue(this.properties.getProperties().isEmpty());
  }
View Full Code Here

  @Test
  public void multipleEntityManagerFactoriesDoNotOverwriteEachOther() {
    EntityManagerFactoryBuilder factory = new EntityManagerFactoryBuilder(
        new HibernateJpaVendorAdapter(), this.properties, null);
    LocalContainerEntityManagerFactoryBean result1 = factory
        .dataSource(this.dataSource1)
        .properties(Collections.singletonMap("foo", "spam")).build();
    assertFalse(result1.getJpaPropertyMap().isEmpty());
    LocalContainerEntityManagerFactoryBean result2 = factory.dataSource(
        this.dataSource2).build();
    assertTrue(result2.getJpaPropertyMap().isEmpty());
  }
View Full Code Here

      this.jta = jta;
      return this;
    }

    public LocalContainerEntityManagerFactoryBean build() {
      LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
      if (EntityManagerFactoryBuilder.this.persistenceUnitManager != null) {
        entityManagerFactoryBean
            .setPersistenceUnitManager(EntityManagerFactoryBuilder.this.persistenceUnitManager);
      }
      if (this.persistenceUnit != null) {
        entityManagerFactoryBean.setPersistenceUnitName(this.persistenceUnit);
      }
      entityManagerFactoryBean
          .setJpaVendorAdapter(EntityManagerFactoryBuilder.this.jpaVendorAdapter);

      if (this.jta) {
        entityManagerFactoryBean.setJtaDataSource(this.dataSource);
      }
      else {
        entityManagerFactoryBean.setDataSource(this.dataSource);
      }

      entityManagerFactoryBean.setPackagesToScan(this.packagesToScan);
      entityManagerFactoryBean.getJpaPropertyMap().putAll(
          EntityManagerFactoryBuilder.this.properties.getProperties());
      entityManagerFactoryBean.getJpaPropertyMap().putAll(this.properties);
      if (EntityManagerFactoryBuilder.this.callback != null) {
        EntityManagerFactoryBuilder.this.callback
            .execute(entityManagerFactoryBean);
      }
      return entityManagerFactoryBean;
View Full Code Here

        return hibernateJpaVendorAdapter;
    }

    @Bean
    public LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean() {
        LocalContainerEntityManagerFactoryBean lcfb = new LocalContainerEntityManagerFactoryBean();
        lcfb.setJpaVendorAdapter(jpaVendorAdapter());
        lcfb.setDataSource(dataSource());
        return lcfb;
    }
View Full Code Here

    }

   
    @Bean
    public LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean( DataSource dataSource  ) throws Exception {
        LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
        em.setDataSource( dataSource );
        em.setPackagesToScan(Customer.class.getPackage().getName());
        em.setPersistenceProvider(new HibernatePersistence());
        Map<String, String> p = new HashMap<String, String>();
        p.put(org.hibernate.cfg.Environment.HBM2DDL_AUTO, "create");
        p.put(org.hibernate.cfg.Environment.HBM2DDL_IMPORT_FILES, "import_psql.sql");
        p.put(org.hibernate.cfg.Environment.DIALECT, PostgreSQLDialect.class.getName());
        p.put(org.hibernate.cfg.Environment.SHOW_SQL, "true");
        em.setJpaPropertyMap(p);
        return em;
    }
View Full Code Here

    }

    @Bean
    public LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean( DataSource dataSource  ) throws Exception {
        LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
        em.setDataSource( dataSource );
        em.setPackagesToScan(Customer.class.getPackage().getName());
        em.setPersistenceProvider(new HibernatePersistence());
        Map<String, String> p = new HashMap<String, String>();
        p.put(org.hibernate.cfg.Environment.HBM2DDL_AUTO, "create");
        p.put(org.hibernate.cfg.Environment.HBM2DDL_IMPORT_FILES, "import_h2.sql");
        p.put(org.hibernate.cfg.Environment.DIALECT, H2Dialect.class.getName());
        p.put(org.hibernate.cfg.Environment.SHOW_SQL, "true");
        em.setJpaPropertyMap(p);
        return em;
    }
View Full Code Here

    public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
        HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        vendorAdapter.setDatabase(Database.HSQL);
        vendorAdapter.setGenerateDdl(true);

        LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
        factory.setJpaVendorAdapter(vendorAdapter);
        factory.setPackagesToScan(Message.class.getPackage().getName());
        factory.setDataSource(dataSource());

        return factory;
    }
View Full Code Here

    }

    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource)
    {
        LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();

        HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        vendorAdapter.setGenerateDdl(Boolean.TRUE);
        vendorAdapter.setShowSql(Boolean.TRUE);

        factory.setDataSource(dataSource);
        factory.setJpaVendorAdapter(vendorAdapter);
        factory.setPackagesToScan("com.sivalabs.springjsfjpa.entities");

        Properties jpaProperties = new Properties();
        jpaProperties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
        factory.setJpaProperties(jpaProperties);

        factory.afterPropertiesSet();
        factory.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
        return factory;
    }
View Full Code Here

TOP

Related Classes of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.