【问题标题】:How to customize hibernate @ElementCollection envers audit table name?如何自定义休眠 @ElementCollection 环境审计表名称?
【发布时间】:2017-08-17 03:03:40
【问题描述】:

我目前使用的是 Hibernate & Envers 版本 5.2.9.Final。我想将 @ElementCollectioncustom table name 一起用于 collection 和 audit table

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

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


其他信息

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

code sn-p 让我的设置更清晰:

@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 按预期生成所有表,但 collecction 审计表名为 'user_references_AUD'我想 获得名称 'user_references_audit' 喜欢其他表。

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


更新

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

【问题讨论】:

    标签: java hibernate-envers


    【解决方案1】:

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

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-22
    • 1970-01-01
    • 2012-08-03
    • 2017-11-25
    • 2020-04-14
    • 2016-12-03
    • 1970-01-01
    • 2014-10-13
    相关资源
    最近更新 更多