Class EntityHistoryRelationEntityListener

java.lang.Object
ch.tocco.nice2.persist.core.api.util.CollectingAfterFlushEntityListener
ch.tocco.nice2.optional.entityhistory.impl.EntityHistoryRelationEntityListener
All Implemented Interfaces:
EntityFacadeListener, CommitListener, EventListener

@Component public class EntityHistoryRelationEntityListener extends CollectingAfterFlushEntityListener
Tracks field changes on existing entities and save them as Entity_history A EntityHistoryConfig/ChildEntityHistoryConfig is required, as an example:

 @Bean
 public EntityHistoryConfig relationEntityHistoryConfig() {
     EntityHistoryConfig config = new EntityHistoryConfig();
     config.setHistoryRelatedEntityName("User");
     config.setRelationsToTrack("relGender");
     return bean;
 }
 
Additionally this listener must be registered for the entity:

 @Bean
 public ListenerContribution<EntityFacadeListener> userEntityHistoryRelationEntityListener(EntityFacadeListener entityHistoryRelationEntityListener) {
      ListenerContribution<EntityFacadeListener> contribution = new ListenerContribution<>();
      contribution.setListener(entityHistoryRelationEntityListener);
      contribution.setFilter("User");
      return contribution;
 }