title: EclipseLink Session customizing - Error
body: <p>In a 3-tier web project using EclipseLink with all business logic on the DB, I need to execute a stored procedure before and after every single stored call, be it procedure or function, in the same session. That's a management decision and I can't do nothing about it.
  So I turned to <a href="http://wiki.eclipse.org/Configuring_a_Session_%28ELUG%29#Configuring_Session_Event_Listeners" rel="nofollow">session customization with Event Listeners</a>, but it is not quite working.</p>
  
  <p>Here is my code in the Session Customizer:
  note: "wrapper" is a custom class wrapping a StoredProcedureCall, "log" is a log4j Logger.</p>
  
  <pre><code>SessionEventAdapter adapter = new SessionEventAdapter() {
      @Override
      public void preExecuteQuery(SessionEvent event) {
          log.debug("Setting environment parameters before query execution.");
  
          [some business code...]
  
          StoredProcedureCall call = wrapper.generateCall();
  
          DatabaseQuery query = new DataModifyQuery(call);
  
          event.getSession().executeQuery(query);
  
          preExecuteQuery(event);
      }
  
      @Override
      public void postExecuteQuery(SessionEvent event) {
          log.debug("Releasing environment parameters after query execution.");
  
          [some business code...]         
  
          StoredProcedureCall call = wrapper.generateCall();
  
          DatabaseQuery query = new DataModifyQuery(call);
  
          event.getSession().executeQuery(query);
  
          postExecuteQuery(event);
      }
  };
  
  session.getEventManager().addListener(adapter);
  </code></pre>
  
  <p>What I get is that line of logging "Setting environment parameters..." gets repeated no less than 600-800 times, then I get a stack overflow error. I have no idea why the preExecuteQuery loops indefinitely. Am I missing something? As far as I know, I'm doing exactly as it seems in the EclipseLink wiki. And before you ask, the behaviour is the same with or without that last line <code>preExecuteQuery(event);</code>.</p>
  
  <p>I also assumed that using the preExecuteQuery and postExecuteQuery events are the right place to put calls in the same session before and after every query, but maybe I'm wrong. I'll also try the PostAcquireUnitOfWork and the PreCommitUnitOfWork events.</p>
  
  <p>Any ideas? Thanks for helping.</p>