Following up by these three topics:
I am looking for a solution to compare and show differences (what was added/edited/deleted) between two revisions of entity.
Let assume that I have entity like below:
@Entity
@Table(name = "MAIN_ENTITY")
@Audited
public class MainEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private Long id;
@Column(name = "NAME")
private String name;
@Column(name = "SHORT_NAME")
private String shortName;
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "MAIN_ENTITY_COUNTER_ID")
private MainEntityCounter mainEntityCounter;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "mainEntity", fetch = FetchType.LAZY, orphanRemoval = true)
@JsonManagedReference
@OrderBy
private Set<Tag> tags = new HashSet<Tag>();
// getters and setters ...
}
Like you can see I added MainEntity (MainEntityCounter and Tag as well) to the audit tables, so I am tracking history of that objects. I found out how to get state of object from database for specific revision:
AuditReader reader = AuditReaderFactory.get(em);
MainEntity mainEntityStart = reader.find(MainEntity.class, mainEntityId, startRevision.intValue());
MainEntity mainEntityEnd = reader.find(MainEntity.class, mainEntityId, endRevision.intValue());
However I have no idea what is the best solution/approach to compare objects mainEntityStart
and mainEntityEnd
.
I thought about transformation above Java objects to JSON objects (or any other kind of tree structure), but I am not sure if it will be good approach.
Thank you for help.
From a functionality perspective, what you're asking about is probably covered in HHH-8058 issue.
I strongly recommend you and others to feel free to vote, offer any input on how you'd like to see the API designed that would work best for your use cases, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With