I have an example for you that creates a data history for a face. Hope this helps.
I had to create a helper interface :
public interface DataHistoryAware { public DataHistory getDataHistory(); public void setDataHistory(DataHistory dataHistory); }
This is a listener implementation :
public class DataHistoryListener { @PrePersist public void setCreateDataHistory(DataHistoryAware model) {
Face Object:
@Entity @EntityListeners(DataHistoryListener.class) @Table(name="person") public class Person implements Serializable, DataHistoryAware { @Column(name = "full_name", length = 255, nullable = false) private String fullName; @OneToOne(cascade = CascadeType.PERSIST) @JoinColumn(name = "data_history_id", nullable = false) private DataHistory dataHistory; public String getFullName() { return this.fullName; } public void setFullName(String fullName) { this.fullName = fullName; } public DataHistory getDataHistory() { return dataHistory; } public void setDataHistory(DataHistory dataHistory) { this.dataHistory = dataHistory; } }
This implementation creates a data history record for the person before it is saved and updates it before merging. The datahistory property has a non-null constraint, so this is the same as your problem with a non-empty contact object property. Hope this was helpful.
lepike
source share