Guest User

Untitled

a guest
Jul 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. @Configuration
  2. @EnableTransactionManagement
  3. @EnableAutoConfiguration
  4. @EnableJpaRepositories(
  5. basePackages = "br.duayres.hudder.domain.repository",
  6. entityManagerFactoryRef = "secondEntityManager",
  7. transactionManagerRef = "secondTransactionManager"
  8. )
  9.  
  10. public class CustomJPAConfig {
  11. @Autowired
  12. private Environment env;
  13.  
  14. @Autowired
  15. DataSource dataSource;
  16.  
  17. @Autowired
  18. JpaVendorAdapter jpaVendorAdapter;
  19.  
  20. @Bean(name = "secondEntityManager")
  21. public EntityManager entityManager() {
  22. EntityManager em = entityManagerFactory().createEntityManager(); //em comes blank/fresh, without any of my properties(yaml)
  23. Map<String,Object> properties = em.getProperties();
  24. System.out.println(properties.toString()); //nothin of application.yml is here!!!! D:
  25. //properties.put("hibernate.default_schema", env.getProperty("spring.jpa.properties.hibernate.cm_schema"));
  26. em.setProperty("hibernate.default_schema", env.getProperty("spring.jpa.properties.hibernate.cm_schema")); //another schema
  27. return em;
  28. }
  29.  
  30. @Bean(name = "secondEntityManagerFactory")
  31. public EntityManagerFactory entityManagerFactory() {
  32. LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
  33. emf.setDataSource(dataSource); //after here i'll change the db jdbcUrl, but no present on this gist...
  34. emf.setJpaVendorAdapter(jpaVendorAdapter);//jpaVendorAdapter comes blank/fresh, without any of my properties(yaml)
  35. emf.setPackagesToScan("br.duayres.domain.entity");
  36. emf.setPersistenceUnitName("notdefault");
  37. emf.afterPropertiesSet();
  38. return emf.getObject();
  39. }
  40.  
  41. @Bean(name = "secondTransactionManager")
  42. public PlatformTransactionManager transactionManager() {
  43. JpaTransactionManager tm = new JpaTransactionManager(); //another time, blank, no properties related
  44. tm.setEntityManagerFactory(entityManagerFactory());
  45. return tm;
  46. }
Add Comment
Please, Sign In to add comment