title: PersistenceExceptionTranslationPostProcessor for JMS DAO
body: <p>I came across Spring's <code>PersistenceExceptionTranslationPostProcessor</code> and this seems perfect since this abstracts the exceptions being thrown in a DAO annotated with <code>@Repository</code>.</p>
  
  <p>Now I have an application which uses JMS (ActiveMQ) instead of a database as a back-end. I'd like to use something like <code>PersistenceExceptionTranslationPostProcessor</code> to translate <code>JMSException</code>s to Spring's <code>DataAccessException</code>.</p>
  
  <p>Before I go and re-invent the wheel I searched the web for such a thing but didn't find it. Maybe I'm using the wrong search keys, so as a second try, does anyone know of something like this existing, or do I have to invent this wheel?</p>
  
  <hr>
  
  <p><strong>Update:</strong></p>
  
  <p>It seems I have to create a <code>PersistenceExceptionTranslator</code> myself. I have done the following:</p>
  
  <p>Implemented <code>PersistenceExceptionTranslator</code> on my abstract JMS DAO:</p>
  
  <pre><code>public abstract class AbstractJmsDao implements PersistenceExceptionTranslator
  {
      public void throwException()
      {
          try
          {
              throw new JMSException("test");
          }
          catch (JMSException ex)
          {
              throw JmsUtils.convertJmsAccessException(ex);
          }
      }
  
      @Override
      public DataAccessException translateExceptionIfPossible(RuntimeException ex)
      {
          // translate exceptions here.
      }
  }
  </code></pre>
  
  <p>Added <code>PersistenceExceptionTranslationPostProcessor</code> to my XML config:</p>
  
  <pre><code>&lt;bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /&gt;
  </code></pre>
  
  <p>Annotated my DAO implementation with <code>@Repository</code>:</p>
  
  <pre><code>@Repository
  public class CustomerJmsDao extends AbstractJmsDao implements CustomerDao
  {
      public void test()
      {
          throwException();
      }
  }
  </code></pre>
  
  <p>However when a <code>RuntimeException</code> is thrown, the <code>translateExceptionIfPossible()</code> never gets hit (checked with breakpoint). I'm obviously missing something here, however I cannot figure out what.</p>