本文介绍了休眠:@AuditTable和@AuditJoinTable有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个冬眠的问题:@AuditTable和@AuditJoinTable有什么区别?它们的用例分别是什么?

I have a hibernate question: what's the difference between @AuditTable and @AuditJoinTable and what are the use cases for each of these?

推荐答案

@AuditTable

@AuditTable

对于每个被审计实体(即,对于至少包含以下内容的每个实体一个审核字段),则创建一个审核表.默认情况下,审核表的名称是通过在原始名称后添加"_AUD"后缀来创建的名称,但是可以通过指定其他后缀/前缀来覆盖(请参见第3章,配置),或者使用@AuditTable批注.

For each audited entity (that is, for each entity containing at least one audited field), an audit table is created. By default, the audit table's name is created by adding a "_AUD" suffix to the original name, but this can be overriden by specifing a different suffix/prefix (see Chapter 3, Configuration) or on a per-entity basis using the @AuditTable annotation.

审核表具有以下字段:

id(如果使用,则可以多于一列嵌入式或多个ID)

id of the original entity (this can be more then one column, if using an embedded or multiple id)

修订号-整数

修订类型-一个小整数

原始实体的审核字段

@AuditJoinTable

@AuditJoinTable

使用这两个注释映射集合时,Hibernate不会生成联接表.但是,Envers必须这样做,因此当您阅读相关实体具有的修订时更改,您不会得到错误的结果.

When a collection is mapped using these two annotations, Hibernate doesn't generate a join table. Envers, however, has to do this, so that when you read the revisions in which the related entity has changed, you don't get false results.

为了能够命名附加的联接表,有一个特殊的注释:@AuditJoinTable,其语义与JPA相似@JoinTable.

To be able to name the additional join table, there is a special annotation: @AuditJoinTable, which has similar semantics to JPA's @JoinTable.

此外,@ AuditTable适用于@Target(value = TYPE),而@AuditJoinTable适用于@Target(value = {FIELD,METHOD}).

Moreover @AuditTable applies on @Target(value=TYPE) while @AuditJoinTable on @Target(value={FIELD,METHOD}).

@AuditJoinTable: https://docs.jboss.org/hibernate/orm/4.2/javadocs/org/hibernate/envers/AuditJoinTable.html

@AuditJoinTable : https://docs.jboss.org/hibernate/orm/4.2/javadocs/org/hibernate/envers/AuditJoinTable.html

@AuditTable: https://docs.jboss.org/hibernate/orm/4.2/javadocs/org/hibernate/envers/AuditTable.html#annotation_type_required_element_summary

@AuditTable :https://docs.jboss.org/hibernate/orm/4.2/javadocs/org/hibernate/envers/AuditTable.html#annotation_type_required_element_summary

这篇关于休眠:@AuditTable和@AuditJoinTable有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 16:08