Hibernate @ManyToMany:REVTYPE仅为添加

Hibernate @ManyToMany:REVTYPE仅为添加,hibernate,many-to-many,hibernate-envers,Hibernate,Many To Many,Hibernate Envers,简言之,我有两个类:Person和attribute: @Entity @Indexed @Table(name="persons") public class Person { private int id; private List<Attribute> attributes; @Id @DocumentId @GeneratedValue @Column(name="person_id") public int getId() { retu

简言之,我有两个类:Person和attribute:

@Entity
@Indexed
@Table(name="persons")
public class Person {

  private int id;
  private List<Attribute> attributes;

  @Id
  @DocumentId
  @GeneratedValue
  @Column(name="person_id")
  public int getId() {
   return id;
  }

  @ManyToMany
  @JoinTable(
    name="attribute_alloc",
    joinColumns={@JoinColumn(name="person_id")},
    inverseJoinColumns={@JoinColumn(name="attribute_id")}
    )
  @Audited
  public List<Attribute> getAttributes() {
   return attributes;
  }

  // other properties, setters and getters...
}


@Entity
@Indexed
@Table(name="attributes")
public class Attribute {

  private int id;
  private List<Person> persons;

  @Id
  @DocumentId
  @GeneratedValue
  @Column(name="attribute_id")
  public int getId() {
   return id;
  }

  @ManyToMany(mappedBy="attributes")
  public List<Attribute> getPersons() {
   return persons;
  }

  // other properties, setters and getters...
}
@实体
@索引
@表(name=“persons”)
公共阶层人士{
私有int-id;
私有列表属性;
@身份证
@文档ID
@生成值
@列(name=“person\u id”)
公共int getId(){
返回id;
}
@许多
@可接合(
name=“attribute\u alloc”,
joinColumns={@JoinColumn(name=“person_id”)},
inverseJoinColumns={@JoinColumn(name=“attribute_id”)}
)
@审计
公共列表getAttributes(){
返回属性;
}
//其他属性、setter和getter。。。
}
@实体
@索引
@表(name=“attributes”)
公共类属性{
私有int-id;
私人名单人员;
@身份证
@文档ID
@生成值
@列(name=“attribute\u id”)
公共int getId(){
返回id;
}
@多个(mappedBy=“属性”)
公众人士名单{
返回人员;
}
//其他属性、setter和getter。。。
}
对于这些类,正确生成了数据库表person、attributes、attribute_alloc、persons_aud、attributes_aud和attribute_alloc_aud

除了亲自审核属性外,所有工作都很好。在表attribute_alloc_aud中,可以正确跟踪更改(例如删除属性并向人员添加新属性),但始终标记为REVTYPE ADD。例如:

  • REV;个人识别码;属性标识REVTYPE
  • 一,;1.1; 0
  • 一,;1.2; 0
  • 二,;1.1; 0
  • 二,;1.5; 0
  • 三,;1.8; 0
结果是,上一次修订中的受审核人员具有属性1、2、5和8。正确答案只有8

怎么了? 谢谢! 致意


Levi

这可能是当您在许多地方更新收藏时,您可能正在清除收藏,然后添加新的收藏。

谢谢!这是一个非常有用的提示!