使用 EclipseLink 如何在创建时禁用自动大写转换

With EclipseLink how do you disable automatic uppercase conversion on creation

当使用 EclipseLink 生成 ddl 时,它总是默认列和 table 名称为大写。 有没有办法全局禁用它而不是设置每个列的名称属性? ,或者让它使用 Class 名称,或者您自己的列名称序列化程序?

非常感谢!

EclipseLink 输出 [EL 配置]:元数据:元素 [warehouseCreatedTimestamp] 的列名称默认为:WAREHOUSECREATEDTIMESTAMP。

实体 [class entities.ActivityFlags] 的 table 名称默认为:ACTIVITYFLAGS。

这可以通过配置禁用: https://www.eclipse.org/eclipselink/documentation/2.5/jpa/extensions/p_jpa_uppercase_column_names.htm

在persistence.xml或代码中(像往常一样)

 <property name="eclipselink.jpa.uppercase-column-names" value="false"/>

如果您想实施选择性规则,请在代码中实施

org.eclipse.persistence.dynamic.DynamicHelper.SessionCustomizer

我的片段按特定规则向表格添加下划线。列也可以。

public class MySessionCustomizer extends 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 = addUnderscores(descriptor.getTableName());
            descriptor.setTableName(tableName);
    }
 }
 }

然后从 persistence.xml

发射它
<property name="eclipselink.session.customizer"  value="pl.....MySessionCustomizer" />

编辑:人们说大写列是正统的。我在一个 JPA 项目中使用 CamelCase,在其他历史依赖项中使用 UPPER。 有些数据库是严格的(MS SQL 服务器),有些则不是(Derby 对于没有撇号的列?)