Created
October 29, 2017 14:09
-
-
Save nikhilbchilwant/2e84cb27ce177d15b9b4ef4621d1487a to your computer and use it in GitHub Desktop.
A skeleton of Hibernate Config class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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