* @return {@link LocalContainerEntityManagerFactoryBean}
*/
@Bean(name = "emf")
@DependsOn("databaseUpdater")
public LocalContainerEntityManagerFactoryBean emf() {
LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
emf.setDataSource(dataSource());
emf.setPersistenceUnitName("ngrinder");
HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
PropertiesWrapper databaseProperties = config.getDatabaseProperties();
Database database = Database.getDatabase(databaseProperties.getProperty(PROP_DATABASE_TYPE));
if (config.isClustered() && !database.isClusterSupport()) {
CoreLogger.LOGGER.error("In cluster mode, H2 is not allowed to use. Please select cubrid as database");
}
hibernateJpaVendorAdapter.setDatabasePlatform(database.getDialect());
hibernateJpaVendorAdapter.setShowSql(false);
emf.setJpaVendorAdapter(hibernateJpaVendorAdapter);
// To search entity packages from other jar files..
emf.setPackagesToScan("empty");
emf.setPersistenceUnitPostProcessors(new PersistenceUnitPostProcessor() {
@Override
public void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo pui) {
Reflections reflections = new Reflections(ControllerConstants.DEFAULT_PACKAGE_NAME);
for (Class<?> each : reflections.getTypesAnnotatedWith(Entity.class)) {
LOGGER.trace("Entity class {} is detected as the SpringData entity.", each.getName());