Is there any way to get EclipseLink to translate camel case to underscores?
For instance, class MyEntity
=> select * from MY_ENTITY
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);
}
}
}
}
}
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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With