Uploaded image for project: 'Hibernate ORM'
  1. HHH-10052

documentation about hashcode and equals not up to date

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 5.0.0.Final
    • Fix Version/s: 5.1.0, 5.2.0, 5.1.1
    • Component/s: documentation
    • Labels:
      None
    • Environment:
      every
    • Last commented by a user?:
      true
    • Sprint:

      Description

      You explain at https://docs.jboss.org/hibernate/orm/5.0/manual/en-US/html/ch04.html#persistent-classes-equalshashcode how to write equals and hashcode.
      Current java versions allow to implement these methods in much shorter and cleaner code using java.util.Objects.equals() and java.util.Objects.hash().

      @Override
      public boolean equals(Object rhs) {
          if (this == rhs)
              return true;
          /**
           * A proxy class does not compare well. So we first have to get the real
           * class
           */
          if (rhs == null || Hibernate.getClass(this) != Hibernate.getClass(rhs))
              return false;
          MyClass that = (MyClass ) rhs;
      
          if (!java.util.Objects.equals(fieldname, that.fieldname))
              return false;
          return true;
      }
      
      @Override
      public int hashCode() {
          return java.util.Objects.hash(fieldname);
      }
      

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: