jpa 添加 表前缀
package my.app;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
public class PrefixPhysicalNamingStrategy extends PhysicalNamingStrategyStandardImpl {
/**
* TODO Make this an injectable application property
*/
public static final String TABLE_NAME_PREFIX = "MY_PREFIX_";
@Override
public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment context) {
Identifier newIdentifier = new Identifier(TABLE_NAME_PREFIX + name.getText(), name.isQuoted());
return super.toPhysicalTableName(newIdentifier, context);
}
}
application.properties
spring.jpa.hibernate.naming.physical-strategy=my.app.PrefixPhysicalNamingStrategy