Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. package com.schooldrive.persistence.config;
  2.  
  3. import org.springframework.context.annotation.Bean;
  4. import org.springframework.context.annotation.ComponentScan;
  5. import org.springframework.context.annotation.Configuration;
  6. import org.springframework.jdbc.datasource.DriverManagerDataSource;
  7. import org.springframework.orm.jpa.JpaTransactionManager;
  8. import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  9. import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
  10. import org.springframework.transaction.annotation.EnableTransactionManagement;
  11.  
  12. import java.util.Properties;
  13.  
  14. /**
  15. * Created by Filip on 21.09.2017.
  16. */
  17. @Configuration
  18. @EnableTransactionManagement
  19. @ComponentScan("com.schooldrive.persistence")
  20. public class SchoolDrivePersistenceContext {
  21.  
  22. @Bean
  23. public String getDbDialect() {
  24.  
  25. return "org.hibernate.dialect.MySQLInnoDBDialect";
  26. }
  27.  
  28. @Bean
  29. public DriverManagerDataSource getDataSource() {
  30.  
  31. DriverManagerDataSource dm = new DriverManagerDataSource();
  32. dm.setDriverClassName("com.mysql.jdbc.Driver");
  33. dm.setUrl("jdbc:mysql://localhost:3306/driving_school");
  34. dm.setUsername("root");
  35. dm.setPassword("");
  36.  
  37. // Properties jpaProperties = new Properties();
  38. // jpaProperties.put("hibernate.connection.CharSet", "utf-8");
  39. // jpaProperties.put("hibernate.connection.useUnicode", true);
  40. // jpaProperties.put("hibernate.connection.characterEncoding", "utf-8");
  41. //
  42. // dm.setConnectionProperties(jpaProperties);
  43.  
  44. return dm;
  45. }
  46.  
  47. @Bean
  48. public LocalContainerEntityManagerFactoryBean getEntityManagerFactory() {
  49.  
  50. LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
  51. em.setDataSource(getDataSource());
  52. em.setJpaVendorAdapter(getJpaVendorAdapter());
  53.  
  54. return em;
  55. }
  56.  
  57. @Bean
  58. public JpaTransactionManager getEntityManager() {
  59.  
  60. JpaTransactionManager jtm = new JpaTransactionManager();
  61. jtm.setEntityManagerFactory(getEntityManagerFactory().getObject());
  62.  
  63. return jtm;
  64. }
  65.  
  66. @Bean
  67. public HibernateJpaVendorAdapter getJpaVendorAdapter() {
  68.  
  69. HibernateJpaVendorAdapter hjva = new HibernateJpaVendorAdapter();
  70. hjva.setDatabasePlatform(getDbDialect());
  71.  
  72. return hjva;
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement