3 Replies Latest reply on Feb 18, 2009 6:18 AM by Wolfgang Knauf

    javax.transaction.RollbackException

    ravi krishna muthireddy Newbie

      Hello,

      I am ramu i am getting following exception while deleting project object.

      org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected 1

      And My piece of code is


      skillids ,bidIds are 2 ArrayLists

      Project deleteProject = manager.find(Project.class, projectId);

      BuyerRating buyerRating=deleteProject.getBuyerRating();
      VendorRating vendorRating =deleteProject.getVendorRating();
      if(buyerRating!=null)
      {
      Query deleteBuyerRatingQuery = manager.createQuery("delete from BuyerRating br where br.project_Id = :id ");

      deleteBuyerRatingQuery.setParameter("id",buyerRating.getProject_Id() );
      deleteBuyerRatingQuery.executeUpdate();
      manager.flush();
      }
      if(vendorRating!=null)
      {

      Query deleteVendorRatingQuery = manager.createQuery("delete from VendorRating vr where vr.project_Id = :id1 ");
      deleteVendorRatingQuery.setParameter("id1",vendorRating.getProject_Id() );
      deleteVendorRatingQuery.executeUpdate();
      manager.flush();
      }

      for(int i :bidIds )
      {
      Bid child = manager.getReference (Bid.class,i );
      Vendor vendor = child.getVendors();
      vendor.getBids().remove(child);
      Project listParents = child.getProject();
      listParents.getBids().remove(child);
      manager.remove(child);
      manager.flush();

      }

      for(int j:skillIds )
      {
      Skill s = manager.getReference(Skill.class, j);
      s.getProjects().remove(deleteProject);
      deleteProject.getSkills().remove(s);
      manager.flush();
      }

      Project project = manager.merge(deleteProject);
      manager.remove(project);

      please tell me where i am doing mistake.

      Thanks
      KRamu

        • 1. Re: javax.transaction.RollbackException
          Wolfgang Knauf Master

          Hi Ramu,

          which line causes the error? I assume it is "Project project = manager.merge(deleteProject);"?

          This one is problematic, because you first load the project, then get the BuyerRating and VendorRating collections, and after this delete the relationships by executing a delete query. This will keep the collections in memory in your loaded project, but they don't exist in the database.

          My suggestion is to change your code this way:
          -First delete BuyerRating and VendorRating
          -After this load the project by "Project deleteProject = manager.find(Project.class, projectId); "
          Currently, you do it the other way round.

          Hope this helps

          Wolfgang

          • 2. Re: javax.transaction.RollbackException
            ravi krishna muthireddy Newbie

            Hi Wolfgang,

            I have tried exactly what u have said. but stll i am getting same exception. For time being i used two methods.

            In First method i am removing all its associated entties like buyerrating,vendorrating,skills,bids.

            In second method simply removing project object.

            But this approch pushing me to go database twice.

            i want to prform this in a single method.

            Any suggessions

            Thanks
            K.Ramu

            • 3. Re: javax.transaction.RollbackException
              Wolfgang Knauf Master

              Hi Ramu,

              please post your modified code (and encapsulate it in "code" tags, see the toolbar in editor for the "Post reply" button).

              Also provide us with the exception and the line number in your own code.

              Best regards

              Wolfgang