java implement equals and hashcode jpa

Solutions on MaxInterview for java implement equals and hashcode jpa by the best coders in the world

showing results for - "java implement equals and hashcode jpa"
Emilia
17 Jun 2016
1@Entity
2public class Book implements Identifiable<Long> {
3 
4    @Id
5    @GeneratedValue
6    private Long id;
7 
8    private String title;
9 
10    @Override
11    public boolean equals(Object o) {
12        if (this == o) return true;
13 
14        if (!(o instanceof Book))
15            return false;
16 
17        Book other = (Book) o;
18 
19        return id != null && 
20               id.equals(other.getId());
21    }
22 
23    @Override
24    public int hashCode() {
25        return getClass().hashCode();
26    }
27 
28    //Getters and setters omitted for brevity
29}
30