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:de.hska.ld.core.config.PersistenceConfig.java

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws SQLException {
    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(jpaVendorAdapter());
    factory.setPackagesToScan("de.hska.ld.*.persistence.domain");
    factory.setDataSource(dataSource());
    //factory.setJpaDialect(new HibernateJpaDialect());

    Properties jpaProperties = new Properties();
    jpaProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("module.core.db.ddl"));
    jpaProperties.setProperty("hibernate.search.default.indexBase",
            env.getProperty("module.core.search.location"));

    factory.setJpaProperties(jpaProperties);
    factory.afterPropertiesSet();/* w  ww.  j  a  v a  2s .  c om*/

    return factory;
}

From source file:it.f2informatica.mysql.MySQLApplicationConfig.java

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setDatabase(Database.MYSQL);
    vendorAdapter.setGenerateDdl(false);
    vendorAdapter.setShowSql(true);//from   w  w w.  jav a 2s  . co  m

    LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
    factoryBean.setPersistenceUnitName(Persistence.PERSISTENCE_UNIT_NAME);
    factoryBean.setJpaVendorAdapter(vendorAdapter);
    factoryBean.setPackagesToScan(DOMAIN_PACKAGE);
    factoryBean.setDataSource(dataSource());
    return factoryBean;
}

From source file:org.axiom_tools.storage.PersistenceContext.java

@Profile("cloud")
@Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean cloudEntityManagerFactory() {
    LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
    em.setDataSource(cloudDataSource.dataSource());
    em.setPackagesToScan(cloudDataSource.modelPackages());
    em.setJpaProperties(cloudDataSource.additionalProperties());
    return em;//w ww.  j a v  a  2  s.c  o m
}

From source file:org.axiom_tools.storage.PersistenceContext.java

@Profile("direct")
@Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean directEntityManagerFactory() {
    LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
    em.setDataSource(directDataSource.dataSource());
    em.setPackagesToScan(directDataSource.modelPackages());
    em.setJpaProperties(directDataSource.additionalProperties());
    return em;//from  w w  w.ja  v  a 2s .c  o  m
}

From source file:co.id.ipb.ilkom.training.db.SpringDataJpaConfiguration.java

@Bean
LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setDataSource(dataSource);
    entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
    entityManagerFactoryBean.setPackagesToScan("co.id.ipb.ilkom");

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

From source file:com.ehealth.infrustructure.RepositoryConfig.java

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

    return entityManagerFactoryBean;
}

From source file:fr.univlorraine.mondossierweb.config.JpaConfig.java

/**
 * EntityManager Factory//from w w  w.j av a2  s .  c  om
 * @return
 */
@Bean
@DependsOn("flyway")
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    localContainerEntityManagerFactoryBean.setPersistenceUnitName(PERSISTENCE_UNIT_NAME);
    localContainerEntityManagerFactoryBean.setPackagesToScan(Favoris.class.getPackage().getName());
    localContainerEntityManagerFactoryBean.setDataSource(dataSource());
    localContainerEntityManagerFactoryBean.setJpaDialect(new EclipseLinkJpaDialect());

    Properties jpaProperties = new Properties();
    /* Active le static weaving d'EclipseLink */
    jpaProperties.put(PersistenceUnitProperties.WEAVING, "static");
    /* Dsactive le cache partag */
    jpaProperties.put(PersistenceUnitProperties.CACHE_SHARED_DEFAULT, String.valueOf(false));
    localContainerEntityManagerFactoryBean.setJpaProperties(jpaProperties);

    EclipseLinkJpaVendorAdapter jpaVendorAdapter = new EclipseLinkJpaVendorAdapter();
    jpaVendorAdapter.setGenerateDdl(false);
    jpaVendorAdapter.setShowSql(false);
    localContainerEntityManagerFactoryBean.setJpaVendorAdapter(jpaVendorAdapter);

    return localContainerEntityManagerFactoryBean;
}

From source file:com.redrisegames.reigninwildWeb.ui.SampleWebUiApplication.java

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

    entityManagerFactory.setDataSource(getDataSource());

    // Classpath scanning of @Component, @Service, etc annotated class
    entityManagerFactory.setPackagesToScan("com.redrisegames.reigninwildWeb.orm");

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

    return entityManagerFactory;
}

From source file:net.ljcomputing.sr.config.JpaConfiguration.java

/**
 * Configured entity manager factory bean.
 *
 * @param dataSource the data source//w  w w  .ja  v a  2  s  . com
 * @param jpaVendorAdapter the jpa vendor adapter
 * @return the local container entity manager factory bean
 */
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource,
        JpaVendorAdapter jpaVendorAdapter) {
    LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
    lef.setDataSource(dataSource);
    lef.setJpaVendorAdapter(jpaVendorAdapter);
    lef.setPackagesToScan("net.ljcomputing.statusReporter");
    return lef;
}

From source file:com.example.spring.boot.config.DatabaseConfig.java

/**
 * Declare the JPA entity manager factory.
 *///from  www  . j  a v  a  2 s  .c  om
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();

    entityManagerFactory.setDataSource(dataSource);

    // Classpath scanning of @Component, @Service, etc annotated class
    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"));
    additionalProperties.put("hibernate.id.new_generator_mappings", "true");
    entityManagerFactory.setJpaProperties(additionalProperties);

    return entityManagerFactory;
}