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

huangapple go评论83阅读模式
英文:

Hibernate Implicit Naming Strategy is ignored when using multiple datasources

问题

根据以下教程,我为两个数据库源创建了两个配置文件:Baeldung-JPA-Multiple-Databases

虽然它可以正常运行,但似乎隐式命名策略被忽略了。这意味着实体 CustomerContact 没有映射到表 customer_contact

我尝试添加了以下两个属性,但没有任何变化:

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);
    ...
}

一个解决方案是使用持久化注解的 name 属性,例如 @Entity(name = "customer_contact"),但我想避免这样做,而是使用隐式映射。

英文:

According to the following tutorial, I created two configruation files for two database sources: 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.

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.

答案1

得分: 1

答案可以在这里找到:https://stackoverflow.com/questions/40509395/cant-set-jpa-naming-strategy-after-configuring-multiple-data-sources-spring-1

所需的属性是:

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

英文:

The answer can be found here: https://stackoverflow.com/questions/40509395/cant-set-jpa-naming-strategy-after-configuring-multiple-data-sources-spring-1

The needed properties are:

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

huangapple
  • 本文由 发表于 2020年8月24日 18:09:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/63558962.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定