title: Entity listeners at repository level - how to also affect cascated entities
body: <p>I've added a listener layer to my project by overriding the <strong>SimpleJpaRepository</strong>, so it looks like this:</p>
  
  <pre><code>@Override
  @Transactional
  public &lt;S extends E&gt; S save(S entity) {
      if (entityInformation.isNew(entity)) {
          persister.beforeCreateListenersFor(entity.getClass()).execute(entity);
          entityManager.persist(entity);
          persister.afterCreateListenersFor(entity.getClass()).execute(entity);
          return entity;
      } else {
          S merged;
          persister.beforeUpdateListenersFor(entity.getClass()).execute(entity);
          merged = entityManager.merge(entity);
          persister.afterUpdateListenersFor(entity.getClass()).execute(entity);
          return merged;
      }
  }
  
  @Override
  public void delete(E entity) {
      Assert.notNull(entity, "Entity must not be null.");
      if (entity instanceof LogicRemovable) {
          ((LogicRemovable) entity).setLogicRemoved(true);
          save(entity);
      } else {
          persister.beforeDeleteListenersFor(entity.getClass()).execute(entity);
          entityManager.remove(entityManager.contains(entity) ? entity : entityManager.merge(entity));
          persister.afterDeleteListenersFor(entity.getClass()).execute(entity);
      }
  }
  </code></pre>
  
  <p>Where <strong>persister</strong> is an interface that provides the listeners for the given class and for the given type (BEFORE_CREATE, AFTER_CREATE etc) in runtime, injecting everything the listener needs.</p>
  
  <p>Everything works amazing, and all I have to do is annotate the listener whith a given annotation.</p>
  
  <p>Problem is: since this layer is on repository level, it is not affecting cascated entities.</p>
  
  <p>So, how can I make it also affect cascated entities?</p>
  
  <p>For me, the perfect solution would be 'just move the layer from repository to X (like entity manager, not sure) and it'll affect both', but I have no idea what that X is.</p>
  
  <p>Or maybe there are another solutions, any are welcome.</p>
  
  <p>Thanks!</p>
  
  <p>-glauber</p>