use of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean 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();
}
use of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean 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;
}
use of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in project irida by phac-nml.
the class IridaApiRepositoriesConfig method entityManagerFactory.
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, JpaVendorAdapter jpaVendorAdapter) {
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
factory.setDataSource(dataSource);
factory.setJpaVendorAdapter(jpaVendorAdapter);
factory.setJpaProperties(dataConfig.getJpaProperties());
factory.setPackagesToScan("ca.corefacility.bioinformatics.irida.model", "ca.corefacility.bioinformatics.irida.repositories.relational.auditing");
return factory;
}
use of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean 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;
}
use of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in project cloudbreak by hortonworks.
the class DatabaseConfig method entityManagerFactory.
@Bean
@DependsOn("databaseUpMigration")
public EntityManagerFactory entityManagerFactory() throws SQLException {
LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
entityManagerFactory.setPackagesToScan("com.sequenceiq.periscope.domain");
entityManagerFactory.setDataSource(dataSource());
entityManagerFactory.setJpaVendorAdapter(jpaVendorAdapter());
entityManagerFactory.setJpaProperties(jpaProperties());
entityManagerFactory.afterPropertiesSet();
return entityManagerFactory.getObject();
}
Aggregations