title: commit changes in try-catch inside @Transactional
body: <p>Consider I have a method doing some stuff and logging mechanism in ActiveRecord pattern style:</p>
  
  <pre><code>@Transactional
  public void doSmt() {
      try {
          someOperation(); // can throw exception
          Logger.logIntoDb(); // if everything is OK
      } catch {Exception e} {
          Logger.logIntoDbWithException(e.getMessage()); // log error into db
  
          throw new MyCustomException(e);
      }
  }
  
  public static void logIntoDbWithException(String message) {
      final LogEntry logEntry = new LogEntry();
      logEntry.setDate(new Date());
      logEntry.setMessage(message);
      logEntry.persist();
  }
  </code></pre>
  
  <p>I want to persist an error message in case of failure, but if I'd rethrow exception in catch clause transaction will be rollbacked and my LogEntry will not be persisted. The only way I see is manually call <code>flush()</code> after <code>persist()</code>.</p>
  
  <p>Is there is a more clean solution to perform this?</p>
  
  <p>Thanks.</p>
  
  <p><strong>UPD:</strong></p>
  
  <p>Since I have a static method which performs persisting I need to apply following hack to accepted answer:</p>
  
  <pre><code>public static void logIntoDbWithException(String message) {
      new Runnable() {
          @Transactional(propagation = Propagation.REQUIRES_NEW)
          public void run() {
              final LogEntry logEntry = new LogEntry();
              logEntry.setDate(new Date());
              logEntry.setMessage(message);
              logEntry.persist();
          }
      }.run();
  }
  </code></pre>