有两个类都经过审核。
@Entity
@Audited
@Table(name = "PLACE")
public class Place {
private long woeId;
private Set<PlaceName> placeNames;
@OneToMany(mappedBy = "place", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@Fetch(FetchMode.JOIN)
public Set<PlaceName> getPlaceNames() {
return placeNames;
}
....
}
@Entity
@Audited
@Table(name = "PLACE_NAME")
@Check(constraints = "NAME_TYPE in ('N', 'V', 'A', 'S', 'P', 'Q', 'A1', 'A2', 'A3', 'FA', 'FI', 'IA', 'IC', 'I2', 'I3', 'NA', 'P1', 'P2')")
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class PlaceName implements Serializable {
private long id;
private String name;
private Place place;
@Id
@SequenceGenerator(name = "SEQ_STORE", sequenceName = "PLACE_NAME_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_STORE")
@Column(name = "NAME_ID", columnDefinition = "NUMBER(12, 0)", nullable = false)
public long getId() {
return id;
}
/**
* @param id
* the id to set
*/
public void setId(long id) {
this.id = id;
}
@Column(name = "NAME", columnDefinition = "NVARCHAR2(512)", nullable = false)
public String getName() {
return name;
}
/**
* @param name
* the name of the {@link Place}
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the {@link Place} this name is associated with
*/
@ManyToOne
@JoinColumn(name = "WOE_ID")
public Place getPlace() {
return place;
}
/**
* @param place
* the {@link Place} this name is associated with
*/
public void setPlace(Place place) {
this.place = place;
}
}
因此,使用
在PLACE_NAME表中添加地名时Place place = session.get(Place.class, new Integer(1));
PlaceName pn = new PlaceName();
pn.setName("ABC");
pn.setPlace(place);
然后,在PLACE_NAME_AUD表中,插入了一个条目,但是在PLACE_AUD表中又添加了一个条目?这是什么原因?
答案 0 :(得分:1)
那是因为看Place
,这个集合发生了变化。这可以通过org.hibernate.envers.revision_on_collection_change
config属性进行配置。有关详细信息,请参阅docs。