Example usage for org.springframework.orm.jpa LocalContainerEntityManagerFactoryBean setPackagesToScan

List of usage examples for org.springframework.orm.jpa LocalContainerEntityManagerFactoryBean setPackagesToScan

Introduction

In this page you can find the example usage for org.springframework.orm.jpa LocalContainerEntityManagerFactoryBean setPackagesToScan.

Prototype

public void setPackagesToScan(String... packagesToScan) 

Source Link

Document

Set whether to use Spring-based scanning for entity classes in the classpath instead of using JPA's standard scanning of jar files with persistence.xml markers in them.

Usage

From source file:pl.java.scalatech.config.JpaEmbeddedConfig.java

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws SQLException {
    LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
    lef.setDataSource(dataSource());//  www  .j  av a  2s  .c  om
    lef.setJpaVendorAdapter(jpaVendorAdapter());
    lef.setJpaPropertyMap(jpaProperties());
    lef.setPackagesToScan(jpaPackage); // eliminate persistence.xml
    return lef;
}

From source file:com.greendot.db.jpa.configuration.JpaDatabaseConfiguration.java

@Bean
public LocalContainerEntityManagerFactoryBean hibernateBackedJpaEntityManagerFactory() {

    final LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactory.setDataSource(dataSource());
    entityManagerFactory.setPersistenceUnitName(environment.getProperty("db.persistenceUnitName"));
    entityManagerFactory.setPackagesToScan(environment.getProperty("db.entityPackageToScan"));

    final JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    entityManagerFactory.setJpaVendorAdapter(vendorAdapter);
    entityManagerFactory.setJpaProperties(jpaHibernateProperties());

    return entityManagerFactory;
}

From source file:com.dhenton9000.birt.configs.DatabaseConfig.java

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();

    entityManagerFactory.setDataSource(dataSource);

    // Classpath scanning of jpa annotated classes
    entityManagerFactory.setPackagesToScan(env.getProperty("entitymanager.packagesToScan"));

    // Vendor adapter
    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    entityManagerFactory.setJpaVendorAdapter(vendorAdapter);

    // Hibernate properties
    Properties additionalProperties = new Properties();
    additionalProperties.put("hibernate.dialect", env.getProperty("hibernate.dialect"));
    additionalProperties.put("hibernate.show_sql", env.getProperty("hibernate.show_sql"));
    //additionalProperties.put(
    //    "hibernate.hbm2ddl.auto", 
    //    env.getProperty("hibernate.hbm2ddl.auto"));
    entityManagerFactory.setJpaProperties(additionalProperties);

    return entityManagerFactory;
}

From source file:com.fantasy.AggregatorConfig.java

@Bean
@Primary/*from ww  w  . j a  v a2s .  c  o m*/
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {

    LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(dataSource());
    em.setPackagesToScan(new String[] { "com.fantasy.stataggregator.entities" });

    JpaVendorAdapter vendorAdapter = new EclipseLinkJpaVendorAdapter();
    em.setJpaVendorAdapter(vendorAdapter);
    em.setJpaProperties(additionalProperties());

    return em;
}

From source file:org.csc.phynixx.spring.integration.config.EntityManagerConfig.java

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws Exception {
    final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    // em.setJtaDataSource(this.dataSource());
    em.setPersistenceUnitName("test");
    em.setPersistenceXmlLocation("classpath:META-INF/bitronix-persistence.xml");
    em.setPackagesToScan(ItemData.class.getPackage().toString());

    final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setDatabasePlatform(this.hibernateDialect());
    vendorAdapter.setShowSql(this.hibernateShowSql());

    em.setJpaVendorAdapter(vendorAdapter);
    em.setJpaProperties(this.jpaProperties());

    return em;/*from   w  w w  .  j a v  a  2 s .co  m*/
}

From source file:com.example.DBConfig.java

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setDataSource(dataSource());
    entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistence.class);
    entityManagerFactoryBean.setPackagesToScan(env.getRequiredProperty(PROP_ENTITYMANAGER_PACKAGES_TO_SCAN));

    entityManagerFactoryBean.setJpaProperties(getHibernateProperties());

    return entityManagerFactoryBean;
}

From source file:com.controller.config.DAOConfig.java

@Bean
public LocalContainerEntityManagerFactoryBean getEntityManagerFactoryBean() {
    LocalContainerEntityManagerFactoryBean lBean = new LocalContainerEntityManagerFactoryBean();

    lBean.setDataSource(dataSource());/*from   w  w w .j  av a2  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:com.searchbox.framework.config.DataConfiguration.java

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();

    entityManagerFactoryBean.setDataSource(dataSource());
    entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
    entityManagerFactoryBean.setPackagesToScan("com.searchbox.framework");

    Properties jpaProperties = new Properties();
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_DIALECT,
            environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_DIALECT));
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_FORMAT_SQL,
            environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_FORMAT_SQL));
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO,
            environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO));
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY,
            environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY));
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_SHOW_SQL,
            environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_SHOW_SQL));

    entityManagerFactoryBean.setJpaProperties(jpaProperties);

    return entityManagerFactoryBean;
}

From source file:org.prueba.DatabaseConfig.java

/**
 * Declare the JPA entity manager factory.
 */// w  w w.j ava2  s. c  o m
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();

    entityManagerFactory.setDataSource(dataSource);

    // Classpath scanning of @Component, @Service, etc annotated class
    entityManagerFactory.setPackagesToScan("erp.entity");

    // Vendor adapter
    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    entityManagerFactory.setJpaVendorAdapter(vendorAdapter);

    // Hibernate properties
    Properties additionalProperties = new Properties();
    additionalProperties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
    additionalProperties.put("hibernate.show_sql", true);
    additionalProperties.put("hibernate.hbm2ddl.auto", "update");
    entityManagerFactory.setJpaProperties(additionalProperties);
    //entityManagerFactory
    return entityManagerFactory;
}

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;
}