- https://stackoverflow.com/questions/78424413/how-to-use-jparepository-method-in-the-jpa-entity-lifecycle-callbacks/78440553#78440553
- https://stackoverflow.com/questions/12155632/injecting-a-spring-dependency-into-a-jpa-entitylistener
- https://github.com/eclipseAce/inject-into-entity-listener/blob/master/src/main/java/com/example/demo/InjectIntoEntityListenerApplication.java
Defining Entity Listener Class Via @EntityListeners
Description: This application is a sample of using the JPA @MappedSuperclass and @EntityListeners with JPA callbacks.
Key points:
- the base class ,
Book, is not an entity, it can beabstract, and is annotated with@MappedSuperclassand@EntityListeners(BookListener.class) BookListenerdefines JPA callbacks (e.g.,@PrePersist)- subclasses of the base class are mapped in tables that contains columns for the inherited attributes and for their own attibutes
- when any entity that is a subclass of
Bookis persisted, loaded, updated, etc the corresponding JPA callbacks are called

