0 Replies Latest reply on Jun 13, 2007 5:20 AM by Torsten Ebeling

    DLQ and caught exception in onMessage

    Torsten Ebeling Newbie

      Hi, I have the following problem: I have a MDB (EJB 3.0 on AS: 4.0.5.GA) that consumes messages from a queue. In the onMessage method I am calling the method of a Stateless Session Bean (injected with SEAM-mechanism).

      public void onMessage( Message msg )
       // extract userId and type from msg - both string variable
       this.requestManager.insert(userId, type) // stateless session bean injected with seam
       catch ( JMSException e ){

      The insert Method is as follows:
      public void insertPemRequest( String userId, String type )
       Person person = new Person( userId, type );
       this.entityManager.persist( examRequest );
       // create business process in jbpm
       catch ( ConstraintViolationException exp ){
       // do nothing, i.e do not kick off new business process
       catch ( EntityExistsException entityEx ) {
       // do nothing, i.e do not kick off new business process

      The Person Bean has unique constraint on userId and type: i.e:
      @Table( uniqueConstraints= {@UniqueConstraint(columnNames={"userId", "type"}) } )
      public class Person {
      // ---- getter/setter for id, name, type

      By catching the EntityExistsException I want to avoid that a business process is kicked off twice for the same person and type. As there might be many messages send and consumed in parallel all requesting to kick off a business process for one person and type combination - this is a good way to control that a business process is kicked off once and once only for a name/type combination.

      Now my problem: The message is still redelivered and send to the DLQ, altough I caught the EntityExistsException. All other exceptions should lead to sending the message to DLQ. But not the EntityExistsException as this is a "tolerated" exception. I know from FAQ

      What type of Exceptions should an MDB throw?
      The quick answer is none.

      But I am catching the exception. right? Or is this correct behaviour and I have to change my design that no EntityExistsException is thrown?