Uploaded image for project: 'Cayenne'
  1. Cayenne
  2. CAY-2660

BigDecimals that differ only in scale are treated as different values causing unneeded updates

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 4.0.2, 4.1.RC2, 4.2.M1
    • 4.2.M2
    • None
    • None

    Description

      Given a column mapping of "DECIMAL(N, M)" to Java BigDecimal, the following code causes an update where it shouldn't (as there are no changes) :

      // assuming the column is "DECIMAL(12, 6)"
      
      BigDecimal bd = new BigDecimal("7890.1");
      
      // save object
      o.setValue(bd);
      o.getObjectContext().commitChanges();
      
      // refetch object - the result will be padded to DB scale - "7890.100000"
      BigDecimalEntity o2 = ObjectSelect.query(BigDecimalEntity.class).selectFirst(runtime.newContext());
      
      // set to the same value and commit
      o2.setValue(bd);
      
      // *** PROBLEM HERE - "UPDATE" SQL is generated, while logically it should have been a noop
      o2.getObjectContext().commitChanges();
      

      I have a PR with a fix based on using "compareTo" instead of "equals" for BigDecimals, but it will require some discussion...

      Attachments

        Activity

          People

            Unassigned Unassigned
            andrus Andrus Adamchik
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1.5h
                1.5h