title: Mark transaction as rollback-only in a MessageDrivenBean without retry the message
body: <p>I have the following MessageDrivenBean:</p>
  
  <pre><code>@MessageDriven(mappedName = "jms/...", activationConfig = {
      @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
      @ActivationConfigProperty(propertyName = "endpointExceptionRedeliveryAttempts", propertyValue = "5"),
      @ActivationConfigProperty(propertyName = "endpointExceptionRedeliveryInterval", propertyValue = "1000")
  })
  public class MyMessageListener implements MessageListener {
  
      @Resource
      private MessageDrivenContext context;
  
      @Override
      @TransactionAttribute(REQUIRED)
      public void onMessage(Message message) {            
      }
  }
  </code></pre>
  
  <p>Inside the <code>onMessage</code> method, I do some processing which is not important here. In certain situations, I want to give up on the processing. In that situations I want to mark the transaction as rollback-only and don't want to retry the processing.</p>
  
  <p>At least on Glassfish 3.1.1, if I call <code>context.setRollbackOnly()</code> on the <code>MessageDrivenContext</code> and end the processing without throwing an exception, the message is redelivered infinitely in very, very short intervals. So that is no option for me.</p>
  
  <p>If I throw a <code>RuntimeException</code> the message is redelivered as I have specified it. It is redelivered 5 times with 1 second interval. But in my case, I don't want to retry the processing at all.</p>
  
  <p>If I simply end the processing without throwing any exception and without calling <code>context.setRollbackOnly()</code>, the transaction is commited, as one would expect. But I need to rollback the transaction because I may have already altered some JPA entities.</p>
  
  <p>The question I have is: How can I mark the transaction as rollback-only without triggering a message redelivery?</p>