Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.8.0
-
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 }