How to use @EqualsAndHashCode
With Include
, Lombok library for Java.
@EqualsAndHashCode.Include( )
How to make Equal
From Lombok, Just add the @EqualsAndHashCode.Include
or @EqualsAndHashCode.Exclude
on required fields
Any class definition may be annotated with @EqualsAndHashCode to let lombok generate implementations of the equals(Object other) and hashCode() methods. By default, it'll use all non-static, non-transient fields, but you can modify which fields are used (and even specify that the output of various methods is to be used) by marking type members with @EqualsAndHashCode.Include or @EqualsAndHashCode.Exclude. Alternatively, you can specify exactly which fields or methods you wish to be used by marking them with @EqualsAndHashCode.Include and using @EqualsAndHashCode(onlyExplicitlyIncluded = true).
@EqualsAndHashCode
@Table(name = "USER")
public class User
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "IDENTITY_USER")
@EqualsAndHashCode.Include
private Long identity;
}