diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/entities/EntitiesConfigurations.java b/hibernate-envers/src/main/java/org/hibernate/envers/entities/EntitiesConfigurations.java index a6575490bd..37439b5cd9 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/entities/EntitiesConfigurations.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/entities/EntitiesConfigurations.java @@ -28,7 +28,7 @@ import java.util.Map; /** * Configuration of the user entities: property mapping of the entities, relations, inheritance. * @author Adam Warski (adam at warski dot org) - * @author Hernán Chanfreau + * @author Hernán Chanfreau */ public class EntitiesConfigurations { private Map entitiesConfigurations; @@ -96,6 +96,10 @@ public class EntitiesConfigurations { return get(entityName) != null; } + public boolean hasAuditedEntities() { + return entitiesConfigurations.size() != 0; + } + public RelationDescription getRelationDescription(String entityName, String propertyName) { EntityConfiguration entCfg = entitiesConfigurations.get(entityName); RelationDescription relDesc = entCfg.getRelationDescription(propertyName); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/EnversIntegrator.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/EnversIntegrator.java index 901a9f98bd..48500c7d30 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/event/EnversIntegrator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/EnversIntegrator.java @@ -60,14 +60,14 @@ public class EnversIntegrator implements Integrator { listenerRegistry.addDuplicationStrategy( EnversListenerDuplicationStrategy.INSTANCE ); final AuditConfiguration enversConfiguration = AuditConfiguration.getFor( configuration ); - // ref HHH-6064 - // todo : if the returned AuditConfiguration says that no things are audited, we should just skip the listener registration - listenerRegistry.appendListeners( EventType.POST_DELETE, new EnversPostDeleteEventListenerImpl( enversConfiguration ) ); - listenerRegistry.appendListeners( EventType.POST_INSERT, new EnversPostInsertEventListenerImpl( enversConfiguration ) ); - listenerRegistry.appendListeners( EventType.POST_UPDATE, new EnversPostUpdateEventListenerImpl( enversConfiguration ) ); - listenerRegistry.appendListeners( EventType.POST_COLLECTION_RECREATE, new EnversPostCollectionRecreateEventListenerImpl( enversConfiguration ) ); - listenerRegistry.appendListeners( EventType.PRE_COLLECTION_REMOVE, new EnversPreCollectionRemoveEventListenerImpl( enversConfiguration ) ); - listenerRegistry.appendListeners( EventType.PRE_COLLECTION_UPDATE, new EnversPreCollectionUpdateEventListenerImpl( enversConfiguration ) ); + if (enversConfiguration.getEntCfg().hasAuditedEntities()) { + listenerRegistry.appendListeners( EventType.POST_DELETE, new EnversPostDeleteEventListenerImpl( enversConfiguration ) ); + listenerRegistry.appendListeners( EventType.POST_INSERT, new EnversPostInsertEventListenerImpl( enversConfiguration ) ); + listenerRegistry.appendListeners( EventType.POST_UPDATE, new EnversPostUpdateEventListenerImpl( enversConfiguration ) ); + listenerRegistry.appendListeners( EventType.POST_COLLECTION_RECREATE, new EnversPostCollectionRecreateEventListenerImpl( enversConfiguration ) ); + listenerRegistry.appendListeners( EventType.PRE_COLLECTION_REMOVE, new EnversPreCollectionRemoveEventListenerImpl( enversConfiguration ) ); + listenerRegistry.appendListeners( EventType.PRE_COLLECTION_UPDATE, new EnversPreCollectionUpdateEventListenerImpl( enversConfiguration ) ); + } } }