3 Replies Latest reply on Mar 30, 2010 5:55 PM by idyoshin

    Commit transaction within web-service request

    cscs
      Hello SEAM community,

      I want to create a Web-Service that is linked to a MDB that processes some kind of Jobs. The flow is as follows:

      1: Incoming Web-Service Request
      2: Create new Job-Object and call persist+flush
      3: Send JobID to Message Bean
      4: Message Bean reads Job object and does some processing in another thread
      5: Wait until Message Bean has completed
      6: Return result to Web-Service consumer and end Request.

      Now I have a problem, as in step 2 the newly created does not get written in the DB even though I use persist and flush. The message bean in step 4 will not be able to read it. The transaction will not be committed until the end of the request. I tried the following to solve this problem:

      Transaction.instance().commit();

      after creating the Job Object. It actually works but afterwards SEAM seams to be broken as it expects to have a transaction. Even when I recreate a new transaction with:

      Transaction.instance().begin();

      SEAM notices that I tampered with it. Is there any nice and clean way to commit a transaction before a request ends? Possibly without completely shutting down SEAMs global transaction handling?


      Thank you for any help in advance,

      Christoph
        • 1. Re: Commit transaction within web-service request
          idyoshin

          I'm using the following approach:  the webservice bean - is the interface, and there is also an event-scoped database controller, in the database controller the whole interaction with database is done. That works for me.



          Kind regards,


          Ilya Dyoshin

          • 2. Re: Commit transaction within web-service request
            cscs

            Hi Ilja,


            thank you for the hint. I have a controller class and set it @Scope(ScopeType.EVENT) but unfortunately it still will not immediately send the newly created Object to the DB. Did you use any other special annotations?

            • 3. Re: Commit transaction within web-service request
              idyoshin

              No.


              simply


              EntityManager em = (EntityManager)Component.getComponent("entityManager, true);
              
              em.persist(obj);
              em.flush();




              the  DBController method is marked as @Transactional, and the Web-service method isn't. Ah,  yeah - I've been using Seam-RESTEasy integration as the web-service.


              Regards,
              Ilya Dyoshin