2010-07-24 67 views
0

我有两个类Person和Attribut,简而言之:@ManyToMany:REVTYPE仅ADD

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

这些类的分贝表者,属性被正确生成attribute_alloc,persons_aud,attributes_aud和attribute_alloc_aud。

除了对Person中的属性进行审计之外,所有的工作都很好。在表attribute_alloc_aud中,正确跟踪更改(例如,删除属性并向人员添加新属性),但始终用REVTYPE ADD标记。例如:

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

后果是,被审计人在最后一次修订具有的属性1,2,5和8正确的将只有8!

怎么了? 非常感谢! 最好的问候

列维

回答

0

这可能是可能在您更新多对多集合你可能会清理出集合,然后添加新的集合。

+0

谢谢!这是一个非常有用的提示! – Levis 2010-08-02 14:41:16