@Bean
public EntityManagerFactoryBean jpaEntityManagerFactory(
final ApplicationContext applicationContext) throws ClassNotFoundException {
EntityManagerFactoryBean emf = new EntityManagerFactoryBean(applicationContext);
logger.info("Starting service: {}", EntityManagerFactory.class.getSimpleName());
final Environment env = applicationContext.getEnvironment();
String[] namespace = env
.getRequiredProperty(ApplicationConstants.APP_NAMESPACE, String[].class);
String hbm2ddl = env.getProperty(DB_SCHEMA, "update");
final Map<String, String> properties = new HashMap<String, String>();
logger.info(" schema's mode: {}", hbm2ddl);
properties.put(AvailableSettings.HBM2DDL_AUTO, hbm2ddl);
// default dialect
Class<?> dialect = DefaultDialect.dialect(env.getRequiredProperty(DataSources.DATABASE));
if (dialect != null) {
properties.put(AvailableSettings.DIALECT, dialect.getName());
}
/**
* Looks for Hibernate properties and set them all.
*/
ReflectionUtils.doWithFields(AvailableSettings.class, new FieldCallback() {
@Override
public void doWith(final Field field) throws IllegalAccessException {
String propertyName = (String) field.get(null);
String propertyValue = env.getProperty(propertyName);
if (!StringUtils.isEmpty(propertyValue)) {
properties.put(propertyName, propertyValue);
}
}
}, new FieldFilter() {