2
有没有什么办法让EclipseLink将驼峰案例转换为下划线?EclipseLink自定义表格和列命名策略
例如,class MyEntity
=>select * from MY_ENTITY
理想的东西预包装我只是把在persistence.xml中的属性。
有没有什么办法让EclipseLink将驼峰案例转换为下划线?EclipseLink自定义表格和列命名策略
例如,class MyEntity
=>select * from MY_ENTITY
理想的东西预包装我只是把在persistence.xml中的属性。
您可以编写一个会话定制程序来执行此操作。首先,创建如下类:
public class MySessionCustomizer implements SessionCustomizer {
@Override
public void customize(Session session) throws SQLException {
for (ClassDescriptor descriptor : session.getDescriptors().values()) {
//Only change the table name for non-embedable entities with no @Table already
if (!descriptor.getTables().isEmpty() && descriptor.getAlias().equalsIgnoreCase(descriptor.getTableName())) {
String tableName = convertToUnderscore(descriptor.getTableName());
descriptor.setTableName(tableName);
for (IndexDefinition index : descriptor.getTables().get(0).getIndexes()) {
index.setTargetTable(tableName);
}
}
}
}
}
然后,您需要注册该定制程序。在部分的persistence.xml中添加以下行:
<property name="eclipselink.session.customizer" value="foo.bar.MySessionCustomizer" />