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();
}
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;
}
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();
}
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;
}
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;
}
Aggregations