Answers for "java implement equals and hashcode jpa"

2

java implement equals and hashcode jpa

@Entity
public class Book implements Identifiable<Long> {
 
    @Id
    @GeneratedValue
    private Long id;
 
    private String title;
 
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
 
        if (!(o instanceof Book))
            return false;
 
        Book other = (Book) o;
 
        return id != null && 
               id.equals(other.getId());
    }
 
    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
 
    //Getters and setters omitted for brevity
}
Posted by: Guest on April-18-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language