EclipseLink自定义表和列的命名策略 [英] EclipseLink custom table and column naming strategy
本文介绍了EclipseLink自定义表和列的命名策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法让EclipseLink将驼峰式大小写转换为下划线?
Is there any way to get EclipseLink to translate camel case to underscores?
例如class MyEntity
=> select * from MY_ENTITY
理想情况下,我可以将预先打包的内容作为属性添加到persistence.xml中.
Ideally something pre-packaged I can just put as a property in persistence.xml.
推荐答案
您可以编写会话自定义程序来做到这一点.首先,创建一个像这样的类:
You can write a session customizer to do that. First, create a class like this:
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中添加以下行:
Then, you need to register this customizer. Add this line in your persistence.xml in <properties>
section:
<property name="eclipselink.session.customizer" value="foo.bar.MySessionCustomizer" />
这篇关于EclipseLink自定义表和列的命名策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文