Hi,
I have a soft deleted entity let’s say user and if soft deletion is performed, I need to change additional attributes.
I have a small example of what I would need. I need to check some condition first where soft deletion will be blocked in some cases. Only if soft deletion will be performed, then I need to anonymize some attributes from the entity. To make it easier let’s say I need to change user.setActive(false) and then save the entity to the database. But with both beforeCommit and afterCommit event listeners I get errors when calling dataManager.save(user).
@EventListener
public void onUserChangedBeforeCommit(final EntityChangedEvent<User> event)
{
if(event.getType()
.equals(EntityChangedEvent.Type.DELETED))
{
if(someCondition())
{
throwExceptionToBlockDeleting();
}
else
{
User user = dataManager.load(event.getEntityId())
.hint(PersistenceHints.SOFT_DELETION, false)
.one();
System.out.println("user: " + user.getUsername()); // does return correct username
user.setActive(false);
dataManager.save(user); // <-- error here
}
}
}
So, how can I make changes of attributes after/during deletion? I’m working with Jmix 2.5.0.
Best regards,
Stefanie