Search in sources :

Example 46 with HibernateJpaVendorAdapter

use of org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter in project ariADDna by StnetixDevTeam.

the class JPAConfiguration method entityManagerFactory.

@Bean
public EntityManagerFactory entityManagerFactory() throws SQLException {
    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setGenerateDdl(true);
    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("com.stnetix.ariaddna.persistence.entities");
    factory.setDataSource(dataSource());
    Properties properties = new Properties();
    properties.put("hibernate.default_schema", "public");
    properties.put("hibernate.hbm2ddl.auto", "create-drop");
    properties.put("hibernate.show_sql", "true");
    properties.put("hibernate.format_sql", "true");
    properties.put("hibernate.use_sql_comments", "true");
    properties.put("hibernate.temp.use_jdbc_metadata_defaults", "false");
    properties.put("hibernate.dialect", dialect);
    factory.setJpaProperties(properties);
    factory.afterPropertiesSet();
    return factory.getObject();
}
Also used : HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) Properties(java.util.Properties) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 47 with HibernateJpaVendorAdapter

use of org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter in project survey by markoniemi.

the class JpaConfig method entityManagerFactory.

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(dataSource());
    JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    em.setJpaVendorAdapter(vendorAdapter);
    em.setJpaProperties(additionalProperties());
    // em.setPackagesToScan("package.where.your.entites.like.CustSys.are.stored");
    return em;
}
Also used : JpaVendorAdapter(org.springframework.orm.jpa.JpaVendorAdapter) HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 48 with HibernateJpaVendorAdapter

use of org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter in project evosuite by EvoSuite.

the class EvoEntityManagerFactory method createEMFWithSpring.

private EntityManagerFactory createEMFWithSpring() {
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    // DriverManagerDataSource uses the context classloader for some reason...
    ClassLoader cl1 = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(EvoEntityManagerFactory.class.getClassLoader());
    dataSource.setDriverClassName(org.hsqldb.jdbcDriver.class.getName());
    dataSource.setUrl("jdbc:hsqldb:mem:.");
    dataSource.setUsername("sa");
    dataSource.setPassword("");
    Thread.currentThread().setContextClassLoader(cl1);
    LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(dataSource);
    // search everything on classpath
    em.setPackagesToScan("");
    em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
    try {
        /*
                The code in this class works fine on Mac, but somehow it crashes on Debian (Lux cluster).
                So, the following is just a workaround, although not fully understood while on Debian
                it was behaving differently
             */
        Field f = LocalContainerEntityManagerFactoryBean.class.getDeclaredField("internalPersistenceUnitManager");
        f.setAccessible(true);
        DefaultPersistenceUnitManager m = (DefaultPersistenceUnitManager) f.get(em);
        m.setDefaultPersistenceUnitRootLocation(null);
    } catch (Exception e) {
        e.printStackTrace();
    }
    Properties properties = new Properties();
    properties.setProperty("hibernate.show_sql", "true");
    properties.setProperty("hibernate.dialect", HSQLDialect.class.getName());
    properties.setProperty("hibernate.connection.shutdown", "true");
    properties.setProperty("hibernate.hbm2ddl.auto", "create-drop");
    properties.setProperty("hibernate.classloading.use_current_tccl_as_parent", "false");
    em.setJpaProperties(properties);
    em.afterPropertiesSet();
    return em.getObject();
}
Also used : HSQLDialect(org.hibernate.dialect.HSQLDialect) Field(java.lang.reflect.Field) DefaultPersistenceUnitManager(org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager) DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) Properties(java.util.Properties) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 49 with HibernateJpaVendorAdapter

use of org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter in project tutorials-java by Artister.

the class JPAConfig method entityManagerFactory.

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setGenerateDdl(true);
    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("org.ko.web");
    factory.setDataSource(dataSource);
    return factory;
}
Also used : HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 50 with HibernateJpaVendorAdapter

use of org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter in project Backend by FredBoat.

the class DatabaseConfiguration method databaseManager.

@Bean
public DatabaseManager databaseManager(HibernateStatisticsCollector hibernateStats, PrometheusMetricsTrackerFactory hikariStats) {
    DatabaseManager databaseManager = new DatabaseManager(hibernateStats, hikariStats, this.dbConf.getHikariPoolSize(), "Quarterdeck", true, this.dbConf.getMainJdbcUrl(), this.dbConf.getCacheJdbcUrl(), (puName, dataSource, properties, entityPackages) -> {
        LocalContainerEntityManagerFactoryBean emfb = new LocalContainerEntityManagerFactoryBean();
        emfb.setDataSource(dataSource);
        emfb.setPackagesToScan(entityPackages.toArray(new String[entityPackages.size()]));
        JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        emfb.setJpaVendorAdapter(vendorAdapter);
        emfb.setJpaProperties(properties);
        // initiate creation of the native emf
        emfb.afterPropertiesSet();
        return emfb.getNativeEntityManagerFactory();
    });
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        if (databaseManager.isCacheConnBuilt()) {
            DatabaseConnection cacheDbConn = databaseManager.getCacheDbConn();
            if (cacheDbConn != null) {
                cacheDbConn.shutdown();
            }
        }
        if (databaseManager.isMainConnBuilt()) {
            databaseManager.getMainDbConn().shutdown();
        }
    }, "databasemanager-shutdown-hook"));
    return databaseManager;
}
Also used : DatabaseManager(com.fredboat.backend.quarterdeck.db.DatabaseManager) JpaVendorAdapter(org.springframework.orm.jpa.JpaVendorAdapter) HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) DatabaseConnection(space.npstr.sqlsauce.DatabaseConnection) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Aggregations

HibernateJpaVendorAdapter (org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter)55 LocalContainerEntityManagerFactoryBean (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)46 Bean (org.springframework.context.annotation.Bean)45 JpaVendorAdapter (org.springframework.orm.jpa.JpaVendorAdapter)6 Properties (java.util.Properties)5 Database (org.springframework.orm.jpa.vendor.Database)4 HashMap (java.util.HashMap)2 DatabaseManager (com.fredboat.backend.quarterdeck.db.DatabaseManager)1 DataSourceBean (de.alpharogroup.springconfig.DataSourceBean)1 JdbcUrlBean (de.alpharogroup.springconfig.JdbcUrlBean)1 Field (java.lang.reflect.Field)1 HashSet (java.util.HashSet)1 DataSource (javax.sql.DataSource)1 lombok.val (lombok.val)1 HSQLDialect (org.hibernate.dialect.HSQLDialect)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Primary (org.springframework.context.annotation.Primary)1