generator-jhipster-entity-audit icon indicating copy to clipboard operation
generator-jhipster-entity-audit copied to clipboard

DELETE action auditing fails on pre-existing entities

Open nickshoe opened this issue 5 years ago • 1 comments

I've enabled the JHipster auditing module on a pre-existing application.

When a pre-existing entity gets deleted without being subject to any prior modification, so without having its lastModifiedDate and lastModifiedBy fields valued by a preceding update action, the EntityAuditEventRepository fails to save the EntityAuditEvent for the delete action.

The auditing framework relies on the fact that lastModifiedDate and lastModifiedBy properties have values in the audited entity, when it's time to persist the audit event, but those properties are null in the situation described above. This is the corresponding console error:

2020-09-15 12:33:21.236 ERROR 2200 --- [ bludesk-task-2] o.h.i.ExceptionMapperStandardImpl        : HHH000346: Error during managed flush [Validation failed for classes [it.blutec.bludesk.domain.EntityAuditEvent] during persist time for groups [javax.validation.groups.Default, ]
List of constraint violations:[
	ConstraintViolationImpl{interpolatedMessage='must not be null', propertyPath=modifiedDate, rootBeanClass=class it.blutec.bludesk.domain.EntityAuditEvent, messageTemplate='{javax.validation.constraints.NotNull.message}'}
]]

This happens because the audit entity modifiedDate and modifiedBy properties gets initialized with the aformentioned entity properties, which are null since the entity never changed before.

I think that the delete action audit entity should have modifiedDate and modifiedBy properties valued "dynamically", based on the current timestamp and principal, rather than copying the values from the entity.

nickshoe avatar Sep 15 '20 12:09 nickshoe

I came across the same problem. Is there a reason, why the fields created_by an created_date have default values in the liquibase addColumn section and last_modified_by and last_modified_date don't? In my opinion the easiest solution to the problem would be to assign them the same default values as for CREATE.

iroCheese avatar Jan 21 '21 17:01 iroCheese

Closing, since we migrate to a new blueprint version. If you found any issue with latest version, please open a new issue.

DanielFran avatar Aug 27 '22 15:08 DanielFran