参考:https://www.jianshu.com/p/fc2c79814956
驼峰与下划线的转化 通用配置:
无修改命名
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
遇到大写加下划线"_" 的命名
spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
如果项目中使用的表既有下划线,又有驼峰,而且还不想使用@Column一个个标识:
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
ReceptionDBConfig.class
// 配置字段
protected Map<String, Object> jpaProperties() {
Map<String, Object> props = new HashMap<>();
props.put("hibernate.physical_naming_strategy", SpringPhysicalNamingStrategy.class.getName());
props.put("hibernate.implicit_naming_strategy", SpringImplicitNamingStrategy.class.getName());
return props;
}
@Bean(name = "receptionEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean kcEntityManagerFactory(EntityManagerFactoryBuilder builder,
@Qualifier("receptionDataSource") DataSource dataSource) {
return builder.dataSource(dataSource).packages("com.icil.elsa.milestone.query.entities.reception")
.persistenceUnit("reception")
.properties(jpaProperties()) // 引入属性配置
.build();
}