Ibernate Envirs: -Addition of Object nella variabile membro della raccolta crea anche una voce nella tabella di controllo della classe principale
-
21-12-2019 - |
Domanda
Ci sono 2 classi che sono state controllate.
@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;
}
}
.
Allora, quando un nome del luogo viene aggiunto nella tabella Place_Name utilizzando
Place place = session.get(Place.class, new Integer(1));
PlaceName pn = new PlaceName();
pn.setName("ABC");
pn.setPlace(place);
.
Quindi, in Place_Name_Aud Tabella, viene inserita una voce, ma anche una voce viene aggiunta in Place_Aud Table?Qual è il motivo?
Soluzione
Questo perché guardando Place
, la collezione è cambiata.Questo è configurabile tramite la proprietà Config org.hibernate.envers.revision_on_collection_change
.Vedi il Docs per i dettagli.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow