Config application Spring Boot JPA with mutible datasource

30 views Asked by At

I config application spring boot jpa with multi database. Follow this answer I have two datasource with two config hibernate.hbm2ddl.auto. Can we put this properties under datasource in application instead of like that?

Like this:

@Bean(name = "externalEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean externalEntityManagerFactory(
        EntityManagerFactoryBuilder builder) {
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("hibernate.hbm2ddl.auto", "update");
    return builder
            .dataSource(externalDataSource())
            .packages("cz.data.external.entity")
            .persistenceUnit(EXTERNAL)
            .properties(properties)
            .build();
}

@Bean(name = "internalEntityManagerFactory")
@Primary
public LocalContainerEntityManagerFactoryBean internalEntityManagerFactory(
        EntityManagerFactoryBuilder builder) {
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("hibernate.hbm2ddl.auto", "create");
    return builder
            .dataSource(internalDataSource())
            .packages("cz.data.internal.entity")
            .persistenceUnit(INTERNAL)
            .properties(properties)
            .build();
}
0

There are 0 answers