I have a table with a composite primary keys including it's own and a FK from other table.
I decided not to use an @IdClass
nor @EmbeddedId
.
class SomeEntity {
@Id
private String someId;
@Id
@ManyToOne(optional = false)
@JoinColumn(name = ...)
private Other other
// other mappings here
}
And Hibernate warns these.
WARN 69752 ... : HHH000038: Composite-id class does not override equals(): ....Some
WARN 69752 ... : HHH000039: Composite-id class does not override hashCode(): ....Some
How can(should) I implement these two methods?
Can(should) I include only these two fields? What about other fields?
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Some that = (Some) o;
return Objects.equals(someId, that.someId) &&
Objects.equals(other, that.other);
}
@Override
public int hashCode() {
return Objects.hash(someId, other);
}