So my problem is that I need to find all the recently deleted entities of a particular class, that is the entities which have been deleted since a particular timestamp. Specifically, I want to find entities deleted within the last hour.
All my entities have a created and updated timestamp which I maintain correctly with a listener:
@NotNull
@Column(name = "updated")
@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
private DateTime updated;
I also use Envers and annotate my entities.
So to guess, my query should start like this:
// Query for deleted bookings
AuditReader reader = AuditReaderFactory.get(entityManager);
AuditQuery query = reader.createQuery()
.forRevisionsOfEntity(Booking.class, false, true)
but I don’t know what to put here to find the deleted Booking’s since a DateTime.
First, get a timestamp for one hour ago (in milliseconds):
Then you can query relative to the timestamp:
to get the revision data. Each
Object[]hasDefaultRevisionEntityor your own class annotated with@RevisionEntity(CustomRevisionListener.class))Bookingin this case)RevisionType, which we know will always beDELin this case