I am using hibernate and need to override equals and hashCode(). I chose to use google-guava\'s equals and hashCode helpers.
I wanted to know if I am missing something
You could actually use the Guava EqualsTester to test your equals and hashCode implementation:
new EqualsTester()
.addEqualityGroup("hello", "h" + "ello")
.addEqualityGroup("world", "wor" + "ld")
.addEqualityGroup(2, 1 + 1)
.testEquals();
It's in the guava testlib.
com.google.guava
guava-testlib
test
Minor change to your implementation:
@Override public boolean equals(final Object obj) {
if(obj == this) return true;
return obj instanceof ImageEntity &&
Objects.equal(getFilePath(), ((ImageEntity) obj).getFilePath());
}