title: How to trigger a hibernate PostActionEventListener from a Session that executes a PreparedStatement?
body: <p>We have a custom class <code>EventListener</code> that implements Hibernate's <code>PostCommitInsertEventListener</code> and <code>PostCommitUpdateEventListener</code> interfaces. Each one is associated with some <code>@Entity</code> and is registered to the application's <code>EntityManagerFactory</code> when the app starts up:</p>
  <pre><code>@PersistenceUnit
  private EntityManagerFactory entityManagerFactory;
  
  //...
  public void register(EventListener listener) {
      SessionFactoryImpl sessionFactory = entityManagerFactory.unwrap(SessionFactoryImpl.class);
      EventListenerRegistry registry = sessionFactory.getServiceRegistry().getService(EventListenerRegistry.class);
      registry.getEventListenerGroup(EventType.POST_COMMIT_INSERT).appendListener(listener);
      registry.getEventListenerGroup(EventType.POST_COMMIT_UPDATE).appendListener(listener);
  }
  </code></pre>
  <p>Somewhere else in the application, there is some code that optimizes a large update query by issuing a <code>PreparedStatement</code> to the database.</p>
  <pre><code>Session session = repository.getEntityManager().unwrap(Session.class);
  session.doWork( connection -&gt; {
          try (PreparedStatement statement = connection.prepareStatement(&quot;... big update statement which affects EntityA&quot;)) {
              // add parameters ...
              equipmentStatement.addBatch();
              equipmentStatement.executeBatch();
          }
      });
  
  session.flush();
  session.clear();
  </code></pre>
  <p>The prepared statement is not caught by Hibernate's event listener for EntityA. Is there any way to trigger the event listeners when executing the prepared statement?</p>