Uploaded image for project: 'Forge'
  1. Forge
  2. FORGE-386

PersistencePlugin needs to generate hashCode and equals based on Id

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Done
    • Icon: Major Major
    • 1.0.0.Beta4
    • None
    • None
    • None

      Domain classes generated by Forge need to override hashCode/equals if they are to be useful in a UI (among other places). This is hard to do if we know nothing about the semantics of the class, but the PersistencePlugin does know something: namely, the Id.

      The following implementation would suffice for my purposes:

      @Override
      public boolean equals(Object that) {

      if (this == that)

      { return true; }

      if (that == null)

      { return false; }

      if (getClass() != that.getClass()) { return false; }

      if (id != null)

      { return id.equals(((Employer) that).id); }

      return super.equals(that);
      }

      @Override
      public int hashCode() {

      if (id != null)

      { return id.hashCode(); }

      return super.hashCode();
      }

      But I'm happy for other implementations too.

            lincolnthree Lincoln Baxter III (Inactive)
            kennardconsulting Richard Kennard (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: