开发者

@ManyToMany: REVTYPE is only ADD

开发者 https://www.devze.com 2023-01-08 21:54 出处:网络
i have the two classes Person and Attribut, in short: @Entity @Indexed @Table(name=\"persons\") public class Person {

i have the two classes Person and Attribut, in short:

@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...
}

For these classes the db 开发者_如何学Gotables persons, attributes, attribute_alloc, persons_aud, attributes_aud and attribute_alloc_aud were correctly generated.

All works well except the audit for the attributes in Person. In the table attribute_alloc_aud the changes (for example removing an attribute and adding a new one to a person) are tracked correctly, but always marked with the REVTYPE ADD. For example:

  • REV; person_id; attribute_id; REVTYPE
  • 1; 1; 1; 0
  • 1; 1; 2; 0
  • 2; 1; 1; 0
  • 2; 1; 5; 0
  • 3; 1; 8; 0

Consequence is that the audited person in the last revision has the attributes 1, 2, 5 and 8. Correct would be only 8!

What's wrong? Thanks a lot! Best regards

Levi


This may be probably when you update the Collection in ManyToMany you may be clearing out collection and then adding new collection.

0

精彩评论

暂无评论...
验证码 换一张
取 消