How to persist EntityDataChangeSet in a table (Entity)
Closed this issue · 10 comments
What should be the correct format of Entity to persist the EntityDataChangeSet, do you have any examples?
I use to store it as as a simple entity where the EntityDataChangeSet is simply serialized as JSON. You may store some additional fields, and also denormalize some for quicker lookups.
LogEntry
private String className; // Classname of the entity being audited
private String pkId; // The primary key
private char operation; // Create, Update, Delete
private Integer userId; // The user that performed the operation
private String json; // The raw JSON data, i.e. the EntityDataChangeSet serialized
Thanks ethlo,
Two more questions, how to avoid the infinite loop when saving LogEntry and how to capture the ID of the tenant that is generated by EclipseLink automatically.
How to capture the tenant is dependant on your stack.
To avoid recursive triggering when storing the entity, you can wrap your listener and decide whether it should be triggering an event or not.
return new DefaultFilteredEntityChangeSetListener(listener,
entity->entity.getClass() != LogEntry.class,
changeSetAndField->true);
@AuditIgnore does not work ?
It is just a marker interface. To make it work, add
return new DefaultFilteredEntityChangeSetListener(listener,
entity->entity.getClass().getAnnotation(AuditIgnore.class) == null,
changeSetAndField->changeSetAndField.getKey().getAnnotation(AuditIgnore.class) == null);
The error below occurs when I simply add the library in pom.xml and test the system without any configuration, only occurs when performing update and delete, in insert the error does not occur.
"Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: javax.validation.ConstraintViolationException: Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event:'preUpdate'. Please refer to embedded ConstraintViolations for details."}"
I am using eclipselink with springboot and feign.
Could you please set a breakpoint and tell me what is the actual constraintviolations inside the javax.validation.ConstraintViolationException
? Thank you!
Operation CREATE SUCESS
Operation DELETE ERROR
ConstraintViolationImpl{interpolatedMessage='can not be null', propertyPath=active, rootBeanClass=class com.company.core.server.domain.AdjustmentReason, messageTemplate='{javax.validation.constraints.NotNull.message}'}
Disabling the dachs Works,,,
This is becoming increasingly hard to debug. To me it sounds like there is nothing triggering flushing of the UOW (Unit of work) and then the bean validation unless Dachs does it. Thus it only triggers the NotNull when Dachs is there. I won't be able to help much more before I have a way to reproduce it.
Is the com.company.core.server.domain.AdjustmentReason.active property indeed null?
Closing this as I received no more feedback after 4 weeks