I have an entity and a Junit, I want to test that update method is working fine, but when I invoke save method from CrudRepository I get a new entry in my table instead of the u
Two ways to make this work
override compareTo method as
@Entity(name = "PERSON")
public class Person implements Comparable{
//... all your attributes goes here
private Integer id;
@Override
public int compareTo(Person person) {
return this.getId().compareTo(person.getId());
}}
or
you need to override equals and hashcode methods in your entity class as below
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (id == null || obj == null || getClass() != obj.getClass())
return false;
Person that = (Person) obj;
return id.equals(that.id);
}
@Override
public int hashCode() {
return id == null ? 0 : id.hashCode();
}