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

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

Introduction

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

Prototype

public void setJpaVendorAdapter(@Nullable JpaVendorAdapter jpaVendorAdapter) 

Source Link

Document

Specify the JpaVendorAdapter implementation for the desired JPA provider, if any.

Usage

From source file:au.com.shawware.sandbox.persistence.JPAConfiguration.java

/**
 * Defines the entity manager factory to use.
 * //from  ww  w.j  ava 2s .c  o  m
 * @return the entity manager factory bean
 * 
 * @throws SQLException error creating the bean
 */
@Bean
public EntityManagerFactory entityManagerFactory() throws SQLException {
    final HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
    adapter.setShowSql(true);
    adapter.setGenerateDdl(true);
    //        adapter.setDatabase(Database.HSQL);

    final LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(adapter);
    factory.setPackagesToScan(Node.class.getPackage().getName());
    factory.setDataSource(dataSource());

    final Properties jpaProperties = new Properties();
    jpaProperties.setProperty("hibernate.show_sql", "true"); // redundant?
    jpaProperties.setProperty("hibernate.format_sql", "true");
    jpaProperties.setProperty("hibernate.hbm2ddl.auto", "create");
    jpaProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
    jpaProperties.setProperty("hibernate.connection.pool_size", "0");
    //        jpaProperties.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
    //        jpaProperties.setProperty("hibernate.hibernate.transaction.factory_class", "org.hibernate.transaction.JDBCTransactionFactory");
    jpaProperties.setProperty("hibernate.connection.url", "jdbc:hsqldb:file:target/data/test;shutdown=true");
    jpaProperties.setProperty("hibernate.connection.username", "sa");
    jpaProperties.setProperty("hibernate.connection.password", "");
    jpaProperties.setProperty("hibernate.connection.autocommit", "true");
    jpaProperties.setProperty("hibernate.jdbc.batch_size", "0");
    jpaProperties.setProperty("hibernate.ejb.entitymanager_factory_name", "sandbox");
    factory.setJpaProperties(jpaProperties);

    // The following method call is important. Things break without it.
    factory.afterPropertiesSet();

    return factory.getObject();
}

From source file:com.peertopark.spring.data.SpringDataConfig.java

@Bean
@DependsOn("migrationManager")
public AbstractEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setDataSource(dataSource());
    entityManagerFactoryBean.setJpaVendorAdapter(jpaVendorAdapter());
    entityManagerFactoryBean.setJpaDialect(jpaDialect());
    return entityManagerFactoryBean;
}

From source file:jpa.JpaConfig.java

@Bean
public EntityManagerFactory entityManagerFactory() {

    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setGenerateDdl(true);//  ww w  .  j  ava  2 s  .co m

    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("things.thing", "types");
    factory.setDataSource(dataSource());
    factory.setMappingResources("thing.hbm.xml");
    factory.afterPropertiesSet();

    return factory.getObject();
}

From source file:ru.develgame.jflickrorganizer.MainClass.java

@Bean
public EntityManagerFactory entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
    emf.setDataSource(dataSource());/*from   www  .j  a  v  a 2  s  .co  m*/
    emf.setJpaVendorAdapter(jpaVendorAdapter());
    emf.setPackagesToScan("ru.develgame.jflickrorganizer.entities");
    emf.setJpaProperties(additionalProperties());
    emf.afterPropertiesSet();

    return emf.getObject();
}

From source file:com.gordondickens.app.infrastructure.config.db.JpaPersistenceCommonConfig.java

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    logger.debug("\n\n************ {} ************\n\n", getDatabaseDialect().getCanonicalName());
    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setGenerateDdl(true);/* ww w .ja va  2s.c  o  m*/
    vendorAdapter.setDatabasePlatform(getDatabaseDialect().getName());
    vendorAdapter.setShowSql(true);

    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan(Employee.class.getPackage().getName());
    factory.setDataSource(dataSource());
    if (getJpaProperties() != null) {
        factory.setJpaProperties(getJpaProperties());
    }
    return factory;
}

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

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

From source file:io.convergencia.training.Application.java

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(dataSource());//from   w w w .  j  a v a  2s .  c om
    em.setJpaVendorAdapter(jpaVendorAdapter());
    em.setPackagesToScan("io.convergencia.training.model");
    return em;
}

From source file:com.MockGatewayApplication.java

@Bean
public EntityManagerFactory entityManagerFactory() {

    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setDatabase(Database.valueOf(dbType));
    vendorAdapter.setShowSql(true);//from   w  w w .  j ava 2 s. c o m
    vendorAdapter.setGenerateDdl(false); //true value not for production !!! update db after entityManager instantiation based on entities
    vendorAdapter.setDatabasePlatform(dbDialect);

    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("com.entity");
    factory.setDataSource(dataSource());
    factory.afterPropertiesSet();

    return factory.getObject();
}

From source file:com.mycompany.configuration.SpringDateConfigMySQL.java

/**
 *  ???//  www.  j av a  2s .  c om
 *
 * @param dataSource ? 
 * @param jpaVendorAdapter   ? 
 * @return  ???
 */
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource,
        JpaVendorAdapter jpaVendorAdapter) {
    LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
    emf.setDataSource(dataSource);
    emf.setPersistenceUnitName("mycompany");
    emf.setJpaVendorAdapter(jpaVendorAdapter);
    // ? ?? ??
    emf.setPackagesToScan("com.mycompany.dto");
    return emf;
}

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