Single entity listener for multiple entities

Jmix version: 2.2.1
Jmix Studio plugin version: 2.2.1-241
IntelliJ IDEA 2024.1 (Ultimate Edition)

Hi Jmix team.

We have several entities that extend from one specific abstract class. That is to say, they have same entity field for all of them which is placed on that abstract class. I need to write single entity listener that it should work for all of them to avoid writing the same listener over and over again. Is it possible?

Also, I need to know which user made the changes on these entities. What solution can you provide for this?

Thanks, in advance!

You can create listener on base entity with generic:

@Component
public class BaseDocEventListener {

    @EventListener
    public void onBaseDocSaving(EntitySavingEvent<? extends BaseDoc> event) {
        event.getEntity().setDocDate(LocalDate.now());
    }
}
1 Like

Creation and last change
https://docs.jmix.io/jmix/data-model/entities.html#audit-traits

or
use Addon Audit :: Jmix Documentation

Most suitable solution for my case. Thanks a lot!

I’ve one more question on it. In Setup tab of Entity Log configuration, there are Auto and Manual checkboxes. What is the main difference of their functionality, can you provide an example to demonstrate it?