英文:
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());
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论