0

In my application, I need to show what rows were deleted. I need to find deleted row details of a particular class.

So far I got a query that returns deleted entity id, how do I get all entity fields?

final AuditQuery query = auditReader.createQuery().forRevisionsOfEntity(Partner.class, false, true);
query.add(AuditEntity.revisionType().eq(RevisionType.DEL));
final List<?> results = query.getResultList();
0

The query you have is what you want, but the issue is that by default Envers doesn't capture the state of the entity when a record is deleted. The only information captured by default is the revision, revision type, and the primary key values of the entity.

What you need is to set org.hibernate.envers.store_data_at_delete to true in your hibernate configuration so that not only will it store the values of the entity I mentioned above, but all audited fields. That will allow the query you are using to return an entity instance with all audited fields populated based on what the entity looked like right before deletion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.