How to use @EqualsAndHashCode
With Include
, Lombok library for Java.
@EqualsAndHashCode.Include( )
How to make Equal
The Include
annotation is used on the member(s) you want to include in the equals
and hashCode
methods. If you want to specify exactly which members should be used (instead of the default of all non-static non-transient members), you could use the onlyExplicitlyIncluded = true
option in the @EqualsAndHashCode
annotation:
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@Table(name = "USER")
public class User
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "IDENTITY_USER")
@EqualsAndHashCode.Include
private Long identity;
}