Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Bean(name = "dataSource")
- public DriverManagerDataSource getDataSource() {
- DriverManagerDataSource dataSource = new DriverManagerDataSource();
- dataSource.setDriverClassName("org.postgresql.Driver");
- dataSource.setUrl("jdbc:postgresql://localhost:5432/vetclinic");
- dataSource.setUsername("postgres");
- dataSource.setPassword("root");
- return dataSource;
- }
- @Autowired
- @Bean(name = "sessionFactory")
- public AnnotationSessionFactoryBean getSessionFactory(DataSource dataSource){
- AnnotationSessionFactoryBean sessionFactory = new AnnotationSessionFactoryBean();
- sessionFactory.setDataSource(dataSource);
- sessionFactory.setPackagesToScan("su.vetclinic.entity");
- Properties hibernateProperties = new Properties();
- hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
- hibernateProperties.setProperty("show_sql", "true");
- hibernateProperties.setProperty("hbm2ddl.auto", "create");
- sessionFactory.setHibernateProperties(hibernateProperties);
- return sessionFactory;
- }
- @Autowired
- @Bean(name="transactionManager")
- public HibernateTransactionManager getTransactionManager(SessionFactory sessionFactory){
- HibernateTransactionManager transactionManager = new HibernateTransactionManager();
- transactionManager.setSessionFactory(sessionFactory);
- return transactionManager;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement