Hibernate envers@AuditMappedBy()应该做什么?

Hibernate envers@AuditMappedBy()应该做什么?,hibernate,annotations,hibernate-envers,Hibernate,Annotations,Hibernate Envers,我使用的是HibernateEnvers4.3.11最终版本 我看到文件上说: 要正确审核与Envers的此类关系,可以使用 @AuditMappedBy注释。它使您能够指定反向 属性(使用mappedBy元素)。对于索引集合, 索引列还必须映射到引用的实体中(使用 @列(insertable=false,updateable=false),并使用 positionMappedBy。此批注将仅影响Envers的方式 有效。请注意注释是实验性的,可能会更改 将来 文档中所说的“指定反向属性”是什么

我使用的是HibernateEnvers4.3.11最终版本

我看到文件上说:

要正确审核与Envers的此类关系,可以使用 @AuditMappedBy注释。它使您能够指定反向 属性(使用mappedBy元素)。对于索引集合, 索引列还必须映射到引用的实体中(使用 @列(insertable=false,updateable=false),并使用 positionMappedBy。此批注将仅影响Envers的方式 有效。请注意注释是实验性的,可能会更改 将来

文档中所说的“指定反向属性”是什么意思

我有几个实体,它们的集合具有多个一和多个链接,我想审核这些实体及其关系,并能够检索修订版。但我似乎无法遍历数据向下遍历到要检索的子实体集合,因此我猜我没有审核它们之间的关系连实体都正确吗

所以我想我需要使用
@AuditMappedBy()

但我感到困惑,因为无论是在集合列上使用
@AuditMappedBy(MappedBy=“NAME”)
,还是在实体顶部使用
@audited
,在检索实体时,我都会在审计表和数据中看到相同的结果。我还不明白为什么要使用@AuditMappedBy()

有人能帮我理解
@AuditMappedBy()
的用例吗

表的层次结构示例以及我需要如何遍历子表中的集合:

**TABLE A:**

@Entity()
@Audited
@Table(name = "TABLE_A")

@Column(name = "ID")
private Long id;
@Column(name = "NAME", length = 50)
private String name;

@OneToMany(
            mappedBy = "table_a",
            cascade = {CascadeType.MERGE, CascadeType.PERSIST}
    )
    @org.hibernate.annotations.Cascade(
            {org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DELETE_ORPHAN}
    )
    private Collection<TABLE_B> table_b = new ArrayList<TABLE_B>();




**TABLE B:**


@Entity()
@Audited
@Table(name = "TABLE_B")

@Column(name = "ID")
private Long id;
@Column(name = "NAME", length = 50)
private String name;

@XmlTransient
@ManyToOne()
@JoinColumn(name = "ID_TABLE_B", nullable = false)
private TABLE_A table_a;

@ManyToOne(
        cascade = {CascadeType.MERGE, CascadeType.PERSIST})
@org.hibernate.annotations.Cascade(
        {org.hibernate.annotations.CascadeType.SAVE_UPDATE}
)
@JoinColumn(name = "ID_TABLE_C")
private TABLE_C table_c;

@ManyToOne(
        cascade = {CascadeType.MERGE, CascadeType.PERSIST})
@org.hibernate.annotations.Cascade(
        {org.hibernate.annotations.CascadeType.SAVE_UPDATE}
)
@JoinColumn(name = "ID_TABLE_D", nullable = true)
private TABLE_D table_d;



**TABLE C:**

@Entity()
@Audited
@Table(name = "TABLE_C")

@Column(name = "ID")
private Long id;
@Column(name = "NAME", length = 50)
private String name;


@OneToMany(
        mappedBy = "table_c",
        cascade = {
                CascadeType.REMOVE})
@org.hibernate.annotations.Cascade(
        {org.hibernate.annotations.CascadeType.SAVE_UPDATE,
                org.hibernate.annotations.CascadeType.MERGE,
                org.hibernate.annotations.CascadeType.DELETE_ORPHAN}
)
@XmlTransient
private Collection<TABLE_B> table_b = new HashSet<TABLE_B>();



**TABLE D:**

@Entity()
@Audited
@Table(name = "TABLE_D")

@Column(name = "ID")
private Long id;
@Column(name = "NAME", length = 50)
private String name;

@XmlTransient
@OneToMany(
        mappedBy = "table_d",
        cascade = {CascadeType.MERGE, CascadeType.PERSIST}
)
private Collection<TABLE_B> table_b = new ArrayList<TABLE_B>();
**表A:**
@实体()
@审计
@表(name=“表A”)
@列(name=“ID”)
私人长id;
@列(name=“name”,长度=50)
私有字符串名称;
@独身癖(
mappedBy=“表a”,
cascade={CascadeType.MERGE,CascadeType.PERSIST}
)
@org.hibernate.annotations.Cascade(
{org.hibernate.annotations.CascadeType.SAVE_UPDATE,org.hibernate.annotations.CascadeType.DELETE_ORPHAN}
)
私有集合表_b=new ArrayList();
**表B:**
@实体()
@审计
@表(name=“Table_B”)
@列(name=“ID”)
私人长id;
@列(name=“name”,长度=50)
私有字符串名称;
@XmlTransient
@ManyToOne()
@JoinColumn(name=“ID\u TABLE\u B”,null=false)
专用表A表A;
@许多酮(
cascade={CascadeType.MERGE,CascadeType.PERSIST})
@org.hibernate.annotations.Cascade(
{org.hibernate.annotations.CascadeType.SAVE_UPDATE}
)
@JoinColumn(name=“ID\u TABLE\u C”)
专用表C表C;
@许多酮(
cascade={CascadeType.MERGE,CascadeType.PERSIST})
@org.hibernate.annotations.Cascade(
{org.hibernate.annotations.CascadeType.SAVE_UPDATE}
)
@JoinColumn(name=“ID\u TABLE\u D”,nullable=true)
专用表D表D;
**表C:**
@实体()
@审计
@表(name=“Table_C”)
@列(name=“ID”)
私人长id;
@列(name=“name”,长度=50)
私有字符串名称;
@独身癖(
mappedBy=“table_c”,
级联={
CascadeType.REMOVE})
@org.hibernate.annotations.Cascade(
{org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.MERGE,
org.hibernate.annotations.CascadeType.DELETE\u ORPHAN}
)
@XmlTransient
私有集合表_b=new HashSet();
**表D:**
@实体()
@审计
@表(name=“Table_D”)
@列(name=“ID”)
私人长id;
@列(name=“name”,长度=50)
私有字符串名称;
@XmlTransient
@独身癖(
mappedBy=“table_d”,
cascade={CascadeType.MERGE,CascadeType.PERSIST}
)
私有集合表_b=new ArrayList();

您能否更新您的帖子,以指定Envers的版本以及遍历不适用的实体映射的示例?AuditMappedBy并不总是必需的,它有点明确地取决于您的用例。