title: MDP JMS Transaction rolls back then reprocesses message in an endless loop
body: <p>If I enable transaction management on my DefaultMessageListenerContainer by specifying <code>sessionTransacted=true</code> or <code>transactionManager=jmsTransactionManager</code>, whenever an exception occurs in the MDP, the transaction is rolled back and the message is placed back on the queue. That then causes the message to be processed again, the transaction to roll back again over and over again so that it creates an endless loop.</p>
  
  <p>I guess my question is ... what am I missing here? Why would you want the message to go back on the queue if it just means it will be processed over and over again?</p>
  
  <pre><code>&lt;!-- jms connection factory --&gt;
  &lt;bean name="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"&gt;
      &lt;property name="jndiName" value="java:ConnectionFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;!-- jms transaction manager --&gt;
  &lt;bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager"&gt;
      &lt;property name="connectionFactory" ref="jmsConnectionFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;!-- Destination for Inbound_Email_Q --&gt;
  &lt;bean name="inboundEmailDestination" class="org.springframework.jndi.JndiObjectFactoryBean"&gt;
      &lt;property name="jndiName" value="queue/inbound_Email_Queue" /&gt;
  &lt;/bean&gt;
  
  &lt;!-- JmsTemplate for Inbound_Email_Q --&gt;
  &lt;bean name="jmsInboundEmailTemplate" class="org.springframework.jms.core.JmsTemplate"&gt;
      &lt;property name="connectionFactory" ref="jmsConnectionFactory" /&gt;
      &lt;property name="defaultDestination" ref="inboundEmailDestination" /&gt;
      &lt;property name="messageConverter" ref="xmlMessageConverter" /&gt;
  &lt;/bean&gt;
  
  &lt;!-- jms asynchronous listener --&gt;
  &lt;bean id="emailMessageServiceMdp" class="org.site.wso.core.jms.EmailMessageServiceMdp" /&gt;
  &lt;bean class="org.springframework.jms.listener.DefaultMessageListenerContainer"&gt;
      &lt;property name="connectionFactory" ref="jmsConnectionFactory"/&gt;
      &lt;!-- &lt;property name="transactionManager" ref="jmsTransactionManager" /&gt;  --&gt;
      &lt;!-- &lt;property name="sessionTransacted" value="true"/&gt;  --&gt;
      &lt;property name="destination" ref="inboundEmailDestination"/&gt;
      &lt;property name="messageListener" ref="messageListener"/&gt;
  &lt;/bean&gt;
  
  &lt;!-- jms message listener adapter --&gt;
  &lt;bean id="messageListener" class="org.springframework.jms.listener.adapter.MessageListenerAdapter"&gt;
      &lt;constructor-arg&gt;
          &lt;bean class="org.site.wso.core.jms.EmailMessageServiceMdp"/&gt;
      &lt;/constructor-arg&gt;
      &lt;property name="messageConverter" ref="xmlMessageConverter"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>And here is my MDP:</p>
  
  <pre><code>public class EmailMessageServiceMdp implements MessageDelegate {
  
      public void handleMessage(Object object) {
  
          EmailMessageRequestVO requestVO = (EmailMessageRequestVO) object;   
  
          try {
              //Service call that throw exception
          } catch (Exception e) {
              throw new ApplicationException(e);
          }
  
      }
  }
  </code></pre>