标签:
ImprovedNamingStrategy在Hibernate5.0.2里面已经移除了。
在stackoverflow上看到了相关的解决方法。。。。
之前的配置是:
<entry key="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy" />
解决办法就是自定义一个类
package im.shs.core.persist.hibernate; import org.apache.commons.lang.StringUtils; import org.hibernate.boot.model.naming.Identifier; import org.hibernate.boot.model.naming.PhysicalNamingStrategy; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; public class ImprovedNamingStrategy implements PhysicalNamingStrategy { @Override public Identifier toPhysicalCatalogName(Identifier identifier, JdbcEnvironment jdbcEnv) { return convert(identifier); } @Override public Identifier toPhysicalColumnName(Identifier identifier, JdbcEnvironment jdbcEnv) { return convert(identifier); } @Override public Identifier toPhysicalSchemaName(Identifier identifier, JdbcEnvironment jdbcEnv) { return convert(identifier); } @Override public Identifier toPhysicalSequenceName(Identifier identifier, JdbcEnvironment jdbcEnv) { return convert(identifier); } @Override public Identifier toPhysicalTableName(Identifier identifier, JdbcEnvironment jdbcEnv) { return convert(identifier); } private Identifier convert(Identifier identifier) { if (identifier == null || StringUtils.isBlank(identifier.getText())) { return identifier; } String regex = "([a-z])([A-Z])"; String replacement = "$1_$2"; String newName = identifier.getText().replaceAll(regex, replacement).toLowerCase(); return Identifier.toIdentifier(newName); } }
配置改为:
<entry key="hibernate.physical_naming_strategy" value="im.shs.core.persist.hibernate.ImprovedNamingStrategy" />
Hibernate从4.3.11.Final到5.0.2.Final时NamingStrateg问题
标签:
原文地址:http://my.oschina.net/SimpleJuly/blog/522784