impement hashcode equals in hiberante

Solutions on MaxInterview for impement hashcode equals in hiberante by the best coders in the world

showing results for - "impement hashcode equals in hiberante"
Claudia
21 Jul 2016
1@Entity
2public class MyEntity {
3 
4    @Id
5    @GeneratedValue(strategy = GenerationType.AUTO)
6    private Long id;
7 
8    private LocalDate date;
9 
10    private String message;
11     
12    @NaturalId
13    private String businessKey;
14 
15    public MyEntity(String businessKey) {
16        this.businessKey = businessKey;
17    }
18     
19    private MyEntity() {}
20     
21    @Override
22    public int hashCode() {
23        return Objects.hashCode(businessKey);
24    }
25 
26    @Override
27    public boolean equals(Object obj) {
28        if (this == obj)
29            return true;
30        if (obj == null)
31            return false;
32        if (getClass() != obj.getClass())
33            return false;
34        MyEntity other = (MyEntity) obj;
35        return Objects.equals(businessKey, other.getBusinessKey());
36    }
37     
38    ...
39}
40