Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. package br.com.casadocodigo.loja.conf;
  2.  
  3. import java.util.Properties;
  4.  
  5. import javax.persistence.EntityManagerFactory;
  6.  
  7. import org.springframework.context.annotation.Bean;
  8. import org.springframework.jdbc.datasource.DriverManagerDataSource;
  9. import org.springframework.orm.jpa.JpaTransactionManager;
  10. import org.springframework.orm.jpa.JpaVendorAdapter;
  11. import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  12. import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
  13. import org.springframework.transaction.annotation.EnableTransactionManagement;
  14.  
  15. @EnableTransactionManagement
  16. public class JPAConfiguration {
  17.  
  18. @Bean
  19. public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
  20. LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
  21. JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
  22.  
  23. factoryBean.setJpaVendorAdapter(vendorAdapter);
  24.  
  25. DriverManagerDataSource dataSource = new DriverManagerDataSource();
  26. dataSource.setUsername("root");
  27. dataSource.setPassword("c3po");
  28. dataSource.setUrl("jdbc:mysql://localhost:3306/casadocodigo");
  29. dataSource.setDriverClassName("com.mysql.jdbc.Driver");
  30.  
  31. factoryBean.setDataSource(dataSource);
  32.  
  33. Properties props = new Properties();
  34. props.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
  35. props.setProperty("hibernate.show_sql", "true");
  36. props.setProperty("hibernate.hbm2ddl.auto", "update");
  37.  
  38. factoryBean.setJpaProperties(props);
  39.  
  40. factoryBean.setPackagesToScan("br.com.casadocodigo.loja.models");
  41.  
  42. return factoryBean;
  43. }
  44.  
  45. @Bean
  46. public JpaTransactionManager transactionManager(EntityManagerFactory emf){
  47. return new JpaTransactionManager(emf);
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement