How to determine which entity invoked method on EntityListener

43 views Asked by At

I have EntityListener class that serves several entities (which extends a base entity).

How can I determine which entity invoked the method of the EntityListener?

public class BaseEntityListener {
    @PreUpdate
    @PrePersist
    public void onUpdate(BaseEntity md) {
        md.timestamp = new Date();

        //Do some code base on the entity type ...
    }
1

There are 1 answers

0
Ronen On

I could resolve this issue this way:

@PostRemove
public void afterDelete(BaseEntity object) {
    String entityName = object.getClass().getSimpleName();
    ...
}

This get the actual implementation.