Have two entities Instrument
and Definition
.
When instrumentCode
changed Envers create audited record only for Instrument
.
I want that when instrumentCode
changed Envers create audited records for both Instrument
and Definition
entities. How it is possible to do, and is it possible?
I’ve played with @AuditedJoinTable, @AuditedMappedBy but without luck.
@Audited
@Getter
@Entity
public class Instrument {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(name = "instrument_code")
protected String instrumentCode;
@ManyToOne(optional = false, fetch = FetchType.LAZY, targetEntity = Definition.class)
@JoinColumn(name = "definition_id", nullable = false)
private Definition definition;
}
//-----
@Audited
@Getter
@Entity
public class Definition {
@Id
@Column(nullable = false)
protected String id;
@OneToMany(mappedBy = "definition",
orphanRemoval = true,
cascade = CascadeType.ALL,
targetEntity = Instrument.class)
private Set<Instrument> instruments = Sets.newHashSet();
}
UPD.
Also I’ve debugged and found that in BaseEnversEventListener.generateBidirectionalCollectionChangeWorkUnits() it found my bidirectional relation but do nothing because entity had not been changed because of code:
// Checking for changes
final Object oldValue = oldState == null ? null : oldState[i];
final Object newValue = newState == null ? null : newState[i];
if ( !EntityTools.entitiesEqual( session, relDesc.getToEntityName(), oldValue, newValue ) ) {
Does it mean that only way to audit Definition
when Instrument
changed is only to completly rewrite envers onUpdate listener?