Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Configuration
- @EnableTransactionManagement
- @EnableAutoConfiguration
- @EnableJpaRepositories(
- basePackages = "br.duayres.hudder.domain.repository",
- entityManagerFactoryRef = "secondEntityManager",
- transactionManagerRef = "secondTransactionManager"
- )
- public class CustomJPAConfig {
- @Autowired
- private Environment env;
- @Autowired
- DataSource dataSource;
- @Autowired
- JpaVendorAdapter jpaVendorAdapter;
- @Bean(name = "secondEntityManager")
- public EntityManager entityManager() {
- EntityManager em = entityManagerFactory().createEntityManager(); //em comes blank/fresh, without any of my properties(yaml)
- Map<String,Object> properties = em.getProperties();
- System.out.println(properties.toString()); //nothin of application.yml is here!!!! D:
- //properties.put("hibernate.default_schema", env.getProperty("spring.jpa.properties.hibernate.cm_schema"));
- em.setProperty("hibernate.default_schema", env.getProperty("spring.jpa.properties.hibernate.cm_schema")); //another schema
- return em;
- }
- @Bean(name = "secondEntityManagerFactory")
- public EntityManagerFactory entityManagerFactory() {
- LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
- emf.setDataSource(dataSource); //after here i'll change the db jdbcUrl, but no present on this gist...
- emf.setJpaVendorAdapter(jpaVendorAdapter);//jpaVendorAdapter comes blank/fresh, without any of my properties(yaml)
- emf.setPackagesToScan("br.duayres.domain.entity");
- emf.setPersistenceUnitName("notdefault");
- emf.afterPropertiesSet();
- return emf.getObject();
- }
- @Bean(name = "secondTransactionManager")
- public PlatformTransactionManager transactionManager() {
- JpaTransactionManager tm = new JpaTransactionManager(); //another time, blank, no properties related
- tm.setEntityManagerFactory(entityManagerFactory());
- return tm;
- }
Add Comment
Please, Sign In to add comment