Advertisement
Guest User

ewr

a guest
Aug 10th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. @Bean(name = "dataSource")
  2. public DriverManagerDataSource getDataSource() {
  3. DriverManagerDataSource dataSource = new DriverManagerDataSource();
  4. dataSource.setDriverClassName("org.postgresql.Driver");
  5. dataSource.setUrl("jdbc:postgresql://localhost:5432/vetclinic");
  6. dataSource.setUsername("postgres");
  7. dataSource.setPassword("root");
  8.  
  9. return dataSource;
  10. }
  11.  
  12. @Autowired
  13. @Bean(name = "sessionFactory")
  14. public AnnotationSessionFactoryBean getSessionFactory(DataSource dataSource){
  15. AnnotationSessionFactoryBean sessionFactory = new AnnotationSessionFactoryBean();
  16. sessionFactory.setDataSource(dataSource);
  17. sessionFactory.setPackagesToScan("su.vetclinic.entity");
  18. Properties hibernateProperties = new Properties();
  19. hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
  20. hibernateProperties.setProperty("show_sql", "true");
  21. hibernateProperties.setProperty("hbm2ddl.auto", "create");
  22. sessionFactory.setHibernateProperties(hibernateProperties);
  23. return sessionFactory;
  24. }
  25.  
  26. @Autowired
  27. @Bean(name="transactionManager")
  28. public HibernateTransactionManager getTransactionManager(SessionFactory sessionFactory){
  29. HibernateTransactionManager transactionManager = new HibernateTransactionManager();
  30. transactionManager.setSessionFactory(sessionFactory);
  31. return transactionManager;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement