如何自定义 hibernate @ElementCollection envers audit table 名称?

How to customize hibernate @ElementCollection envers audit table name?

我目前正在使用 Hibernate & Envers 5.2 版。9.Final。我想将 @ElementCollection 自定义 table 名称 一起用于 集合和审计 table

到目前为止我所知道的是修改默认的 table 名称有多种注释可以使用:对于实体本身,有注释 @Table 和 @SecondaryTable以及相应的envers注解@AuditTable和@SecondaryAuditTable。要更改元素集合的 table 名称,可以使用 @CollectionTable 注释。到目前为止,我还没有找到相应的 envers 注释。所以我的问题是:

如何更改休眠@ElementCollection envers 审计的名称table?


附加信息

在元素集合的 hibernate envers ticket which tracks the adding of auditing support 中,同样的问题在 2013 年被提出但没有得到回答。

一个代码片段使我的设置清晰:

@Entity
@Table(name = "\"user\"")
@SecondaryTable(name = "\"user_secondary\"")
@Audited
@AuditTable("\"user_audit\"")
@SecondaryAuditTable(secondaryTableName = "user_secondary",
        secondaryAuditTableName = "\"user_secondary_audit\"")
public class User {

    // ... stuff like id and other fields ...

    @ElementCollection
    @CollectionTable(name = "\"user_references\"")
    private Map<String, Long> references = new HashMap<>();
    // TODO FIXME how to get a custom name for the audit table?

    // ... more stuff like getters and setters
}

Hibernate 按预期生成所有 tables,但 collecction audit table 被命名为 'user_references_AUD'I想 像其他 table 一样得到名字 'user_references_audit'

我也知道影响审核的全局设置table前缀或后缀,但这只是我用例的最后手段。


更新

按照建议,我向 Hibernate JIRA 添加了一个 feature request

那是因为Envers对@CollectionTable没有补码。

欢迎您添加 JIRA 要求我们添加补充注释,我可以查看添加功能所需的内容。乍一看,它不需要太多,因为它只需要输入生成的 Envers 实体 table 集合中间实体的名称。