0 Replies Latest reply on Oct 4, 2006 6:46 PM by tabbe

    Transaction & Method calls

    tabbe

      Hi at all,

      I have a problem, I have an EJB which has an entry method that is called by the container. I dont want this method to throw an exception, so I put the business code in another method in the same bean:

       @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
       public Response processRequest2(Request request) throws Exception
       {
       checkPolicy(request);
      
       checkExtensions(request);
      
       // initialize the info object
       Info info = new Info(request);
      
       // set serial number
       SerialNumber sn = em.find(SerialNumber.class, Long.valueOf(0));
       if (sn == null)
       {
       sn = new SerialNumber(0);
       em.persist(sn);
       logger.log(AdLevel.INFO, "Serial number not found, creating entity");
       }
       BigInteger serial = sn.getSerial();
      
      serial.toString());
       info.setSerialNumber(serial);
       sn.setSerial(serial.add(BigInteger.ONE));
      
       if (true)
       throw new CryptoProcessorException();
      
      
      ...
      


      This method does not catch the CryptoProcessorException which is annotated with the rollback=true property.

      The calling method looks like this:

       public Type processRequest(Type request) throws Exception
       {
       try
       {
       return processRequest2((Request)request);
       }
       catch (Exception e)
       {
       return new Type(e);
       //throw e;
       }
       }
      


      In this case, the serial number is always increased!!!
      I'm a bit confused.

      But if I rethrow the Exception, the rollback works.

      Isnt there a possibility to catch the exception in the processRequest method and to get the rollback working?

      Thanks
      Thomas