![](/img/trans.png)
[英]Changing naming strategy of @Table and @Column with EclipseLink to lower-case
[英]EclipseLink custom table and column naming strategy
有沒有辦法讓EclipseLink將camel case轉換為下划線?
例如, 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);
}
}
}
}
}
然后,您需要注冊此自定義程序。 在<properties>
部分的persistence.xml中添加以下行:
<property name="eclipselink.session.customizer" value="foo.bar.MySessionCustomizer" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.