spring boot jpa 忽略表名大小写问题
spring boot 2.3.5 mysql 8
由于某个项目中表名都是大写,代码中的table注解都是小写,解决方案
配置类
@Component
public class IgnoreCaseConfig extends PhysicalNamingStrategyStandardImpl {
private static final long serialVersionUID = 1383021413247872469L;
@Override
public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment context) {
// 将表名全部转换成大写
String tableName = name.getText().toUpperCase();
return Identifier.toIdentifier(tableName);
}
}
yml文件
jpa:
show-sql: true
hibernate:
naming:
physical-strategy: cn.onefox.kettle.IgnoreCaseConfig
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
properties:
hibernate:
format_sql: true
show_sql: true
current_session_context_class: org.springframework.orm.hibernate5.SpringSessionContext
dialect: org.hibernate.dialect.MySQL5Dialect
在启动查询都不会因为大小写问题而查不到表了