12 Replies Latest reply on May 13, 2011 7:19 AM by Praveen Pasi-Oracle

    Error in changing row attribute value

    Praveen Pasi-Oracle
      Hi,
      I am using JDeveloper 11.1.1.4 and developing a project using ADF-BC.
      In my application,I am displaying an adf table from DataControl->view object.
      The view object is based on an entity object which has composite primary key [Ex: Name and Rank]
      I have an requirement to swap selected row and its previous row's rank values on click of a button.
      I have written following code to achieve this.

      public void swapRows(ActionEvent actionEvent) {

      ViewObject rscMapVo = getRscMapViewObj();
      Row currRow = rscMapVo.getCurrentRow(); //------------->Current Row
      int currRowIndex = rscMapVo.getRangeIndexOf(currRow);
      Row prevRow = getRscMapVoIter().getRowSetIterator().getRowAtRangeIndex(currRowIndex - 1); // ------------> Previous Row
      Long currRowRank = ((Number)currRow.getAttribute("Rank")).longValue();
      Long prevRowRank = ((Number)prevRow.getAttribute("Rank")).longValue();
      //Actual Swapping

      prevRow.setAttribute("Rank", new Number(currRowRank));
      currRow.setAttribute("Rank", new Number(prevRowRank));

      adfFacesContext.addPartialTarget(tblRSCMap);

      }//End of method



      This is giving me the exception

      1)Rank     Too many objects match the primary key oracle.jbo.Key[Group_1 7 ]. [Name is Group_1 and Rank is 7]
      2)Rank     Too many objects match the primary key oracle.jbo.Key[Group_1 8 ] .[Name is Group_1 and Rank is 8]


      If instead of actual rank values I update it to some random number it updates properly. i.e for example prevRow.setAttribute("Rank", new Number(900)); and currRow.setAttribute("Rank", new Number(800));

      The exception occurs when I change one row value with a value that is already present in other row there by giving unique constraint problem.

      How to overcome this problem??
      Is there any other way of implemeting this solution.

      I want the changed attribute values to commit to DB only after final commit but not immediately.

      Please advice/suggest.

      Thanks,
      Praveen