Skip to content

Instantly share code, notes, and snippets.

@nikhilbchilwant
Created October 29, 2017 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikhilbchilwant/2e84cb27ce177d15b9b4ef4621d1487a to your computer and use it in GitHub Desktop.
Save nikhilbchilwant/2e84cb27ce177d15b9b4ef4621d1487a to your computer and use it in GitHub Desktop.
A skeleton of Hibernate Config class
@Configuration
@ComponentScan(value={"package"})
@EnableTransactionManagement
public class HibernateConfig {
@Autowired
private Environment env;
private Properties getHibernateProperties() throws AppConfigException{
//read properties from config file. I'm not not pasting whole source code here
return properties;
}
@Bean
public LocalSessionFactoryBean getSessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setPackagesToScan(new String[] { Constants.COMPONENT_SCAN_PACKAGE.toString() });
sessionFactory.setHibernateProperties(getHibernateProperties());
return sessionFactory;
}
@Bean
public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) {
HibernateTransactionManager txManager = new HibernateTransactionManager();
txManager.setSessionFactory(sessionFactory);
return txManager;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment