JPA(休眠)和自定义表前缀
是否可以覆盖 JPA/Hibernate 中的表名,以便为所有项目实体添加通用前缀?例如,能够在所有 JBPM 5 表前面加上“JBPM5_”前缀。
接受的答案示例:
public class JBPM5NamingStrategy extends ImprovedNamingStrategy {
public String classToTableName(String className) {
return StringHelper.unqualify(className);
}
public String propertyToColumnName(String propertyName) {
return propertyName;
}
public String tableName(String tableName) {
return "JBPM5_" + tableName;
}
public String columnName(String columnName) {
return columnName;
}
public String propertyToTableName(String className, String propertyName) {
return "JBPM5_" + classToTableName(className) + '_'
+ propertyToColumnName(propertyName);
}
}