简体   繁体   English

使用多个数据源时忽略 Hibernate 隐式命名策略

[英]Hibernate Implicit Naming Strategy is ignored when using multiple datasources

According to the following tutorial, I created two configruation files for two database sources: Baeldung-JPA-Multiple-Databases根据以下教程,我为两个数据库源创建了两个配置文件: Baeldung-JPA-Multiple-Databases

It works fine, but it seems that the implicit naming strategy is ignored.它工作正常,但似乎忽略了隐式命名策略。 That means that an Entity CustomerContact is not mapped to a table customer_contact .这意味着实体CustomerContact未映射到表customer_contact

I tried to add the following two properties, but nothing changes:我尝试添加以下两个属性,但没有任何变化:

public LocalContainerEntityManagerFactoryBean primaryEntityManager() {
    ...
    properties.put("hibernate.naming.implicit-strategy", "org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy");
    properties.put("hibernate.naming.physical-strategy", "org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy");
    em.setJpaPropertyMap(properties);
    ...
}

One solution would be to use the name attribute of the persistence annotations, like @Entity(name = "customer_contact") , but I would like to avoid that and use the implicit mapping instead.一种解决方案是使用持久性注释的 name 属性,例如@Entity(name = "customer_contact") ,但我想避免这种情况并改用隐式映射。

The answer can be found here: Can't set JPA naming strategy after configuring multiple data sources (Spring 1.4.1 / Hibernate 5.x)答案可以在这里找到: 配置多个数据源后无法设置JPA命名策略(Spring 1.4.1 / Hibernate 5.x)

The needed properties are:所需的属性是:

props.put("hibernate.physical_naming_strategy", SpringPhysicalNamingStrategy.class.getName());
props.put("hibernate.implicit_naming_strategy", SpringImplicitNamingStrategy.class.getName());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM