title: Catch Exceptions inside a Message Driven Bean (MDB)
body: <p>How must I handle exceptions inside a mdb? I have the funny feeling that the exception happens after the try catch block so I'm not able to catch and log it. Glassfish v3 decides to repeat the whole message. It runns into a infinite loop and writes lot's of logfiles on the harddrive.</p>
  
  <p>I'm using Glassfishv3.01 + Eclipselink 2.0.1</p>
  
  <pre><code>public class SaveAdMessageDrivenBean implements MessageListener {
  
      @PersistenceContext(unitName="QIS") 
      private EntityManager em;
  
      @Resource
      private MessageDrivenContext mdc;
  
      public void onMessage(Message message) {
          try {
              if (message instanceof ObjectMessage) {
                  ObjectMessage obj = (ObjectMessage)message;
                  AnalyzerResult alyzres = (AnalyzerResult)obj.getObject();
                  save(alyzres);
              }
          } catch (Throwable e) { 
              mdc.setRollbackOnly();
              log.log(Level.SEVERE, e);
          }
      }
  
      @TransactionAttribute(TransactionAttributeType.REQUIRED)
      private void save(AnalyzerResult alyzres) throws PrdItemNotFoundException {
  
         Some s = em.find(Some.class, somepk);
         s.setSomeField("newvalue");
  
         // SQL Exception happens after leaving this method because of missing field for ex.
      }
  }    
  </code></pre>