The Entity Listener allows you to respond to the various changes to an entity that are made, e.g. when saving an entity to log this saving action. You can use the Entity Listener wizard to generate the required entity listener so that you only have to enter the code that has to be executed after triggering the event. A total of seven events are supported:
CarListener.java: Under Project Management > Entities, the wizard generates the CarListener.java class and adds the annotation @EntityListeners(CarListener.class) to the Car entity.
package com.company.examples.entities; import javax.persistence.PrePersist; public class CarListener { @PrePersist public void prePersist(Car car) { // Action before the entity is persisted } } |