Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-4894

'includes' attribute in EqualsAndHashCode

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.8.0
    • 1.8.1
    • None
    • None

    Description

      This is to continue the late discussion in GROOVY-2879 which has stopped since the issue was closed.

      So, the use case for 'includes' attribute usefulness in @EqualsAndHashCode is a typical JPA Entity, which should implement the equivalence on the natural key basis, and usually the natural key is one or two properties, while the entity can contain dozens of properties, and all of them have to be listed in 'excludes' at the moment.

      Example:
      Entity Person, where firstName and lastName represent the natural key, we don't want anything else in equals()

      Using current implementation
      @Entity
      @EqualsAndHashCode(excludes = 'id,age,email,address,occupation,spouse,contacts,interests,relatives,friends,whatever')
      class Person {
          @Id int id
          String firstName, lastName
      
          def age, email, address, occupation, spouse, contacts, interests, relatives, friends, whatever
      } 
      
      Proposed
      @Entity
      @EqualsAndHashCode(includes= 'firstName,lastName')
      class Person {
          @Id int id
          String firstName, lastName
      
          def age, email, address, occupation, spouse, contacts, interests, relatives, friends, whatever
      } 
      

      Attachments

        Activity

          People

            paulk Paul King
            pawlom Pavlo Morgunyuk
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: