I would like to update my entity before it gets deleted (because a DB Trigger will use that value later).
So I tried this inside my EntityListener:
@PreRemove
void onRemove(Object entity) {
CurrentUser currentUser = CDI.current().select(CurrentUser.class).get();
if (currentUser != null && entity instanceof BaseEntity) {
BaseEntity baseEntity = (BaseEntity) entity;
baseEntity.deletedBy = currentUser.userId;
baseEntity.persistAndFlush();
}
}
However, the changes are not persisted to the DB before the deletion - presumably because the deletion transaction is already started.
How can I achieve this ?