TL;博士
将以下内容添加到您的文件中:application.yml
spring:
jpa:
hibernate:
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
或您的 :application.properties
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
详细答案
正如Spring Boot 1.4发行说明所述:
SpringNamingStrategy
不再使用,因为Hibernate 5.1已经删除了对旧接口的支持。一个新的现在是自动配置的,它与Hibernate的默认.这应该非常接近(如果不相同)Spring Boot 1.3默认值,但是,您应该在升级时检查数据库模式是否正确。NamingStrategy
SpringPhysicalNamingStrategy
ImplicitNamingStrategy
这个新功能遵循了Spring推荐的命名约定。无论如何,如果您想完全控制物理命名,最好使用 .您可以通过将以下内容添加到您的PhysicalNamingStrategy
org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
application.yml
spring:
jpa:
hibernate:
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
注释将被忽略并创建表,然后导致Spring Social具有嘶嘶声。user_connection
的 apply
方法是理解此行为的关键:SpringPhysicalNamingStrategy
private Identifier apply(Identifier name, JdbcEnvironment jdbcEnvironment) {
if (name == null) {
return null;
}
StringBuilder builder = new StringBuilder(name.getText().replace('.', '_'));
for (int i = 1; i < builder.length() - 1; i++) {
if (isUnderscoreRequired(builder.charAt(i - 1), builder.charAt(i),
builder.charAt(i + 1))) {
builder.insert(i++, '_');
}
}
return getIdentifier(builder.toString(), name.isQuoted(), jdbcEnvironment);
}
private boolean isUnderscoreRequired(char before, char current, char after) {
return Character.isLowerCase(before) && Character.isUpperCase(current)
&& Character.isLowerCase(after);
}
它基本上用下划线替换了任何和大小写更改(看看isUnderscoreRequired
方法)。.