我目前正在使用 Hibernate & Envers version 5.2.9.Final . 对于 collection and the audit table ,我想将 @ElementCollection 与 custom table name 一起使用 .
到目前为止我所知道的是修改默认表名称有多种注释可供使用:对于实体本身,有注释@ Table和@SecondaryTable以及相应的envers注释@AuditTable和@SecondaryAuditTable . 要更改元素集合的表名,可以使用@CollectionTable注释 . 到目前为止,我还没有找到相应的envers注释 . 所以我的问题是:
How can I change the name for a hibernate @ElementCollection envers audit table?
Additional info
在元素集合的hibernate envers ticket which tracks the adding of auditing support中,2013年回答了同样的问题,但没有回答 .
A code snippet 让我的设置清晰:
@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 audit table is named 'user_references_AUD' 虽然我希望得到其他表的名称 'user_references_audit' .
我也知道影响审计表前缀或后缀的全局设置,但这只是我的用例的最后手段 .
Update
正如所建议的那样,我向Hibernate JIRA添加了一个feature request .
1 回答
那是因为Envers没有
@CollectionTable
的补充 .欢迎您添加JIRA,请求我们添加补充注释,我可以查看添加功能所需的内容 . 一目了然,它不应该需要太多,因为它只需要输入生成的集合中间实体的Envers实体表名称 .