0 Replies Latest reply on Jun 5, 2008 4:41 PM by connysvensson

    No transaction in progress

    connysvensson

      I'm using Seam 2.0.2SP1 and GWT 1.5RC1. I'm having some problems merging entities. I get an TransactionException No transaction in progress. I've done a project in Seam before using the regular JSF presentation layer but now I'm moving to GWT. Is there anything special I need to setup for persistence management to get it to work? Querying the backend works fine but not merging or persisting. Here is my code:



      @Scope(ScopeType.EVENT)
      @Name("SaveEmployee")
      public class SaveEmployeeHandler extends RpcEventHandler<SaveEmployee, RpcEntityResult> {
           
          @Logger Log log;
          
          @In EntityManager entityManager;
           
          @Override
          @Transactional(TransactionPropagationType.REQUIRED)
          protected RpcEntityResult doHandle(SaveEmployee request) throws RpcException {
              log.info("Saving employee with id: #0", request.getEntity().getId());
              
              // Updated entity from client
              Employee clientEmp = (Employee) request.getEntity();
              
              // Get attached entity from backend
              Employee dbEmp = (Employee) entityManager.find(Employee.class, clientEmp.getId());
              
              // Merge client and backend entities (this should be done with hibernate4gwt)
              dbEmp.setFirstName(clientEmp.getFirstName());
              dbEmp.setLastName(clientEmp.getLastName());
                    
              try {
                  //entityManager.getTransaction().begin();
                  //Transaction.instance().begin();
                  entityManager.joinTransaction(
                  dbEmp = entityManager.merge(dbEmp);
                  entityManager.flush();
              } catch (Exception ex) {
                  throw new RpcException(ex);
              }
            
              return new RpcEntityResult(dbEmp);
          }
           
      }



      It crashes on the flush operation. The commented lines are things I've tried to start a transaction but haven't worked. I'm currently using the following code and it works but it feels like it shouldn't be necessary, it's not the regular Seam way.



      Session session = (Session) entityManager.getDelegate();
      session.saveOrUpdate(dbEmp);
      session.flush();



      Anyone with an idea why the Seam container doesn't start a transaction automatically for me as it should? I read somewhere that it starts the transaction in the JSF lifecycle but I'm not using JSF. I have marked the method as Transactional so that should take care of it, right?