Given the following:
@Entity
public class Parent implements Serializable {
@Id
private Long id;
// mapped ManyToOne below...
private List<Child> children = new ArrayList<Child>();
...
}
Is it a bad practice to have Parent.equals() and Parent.hashCode() use only id? I understand that Child.equals() and Child.hashCode() should use a immutable set of attributes for a "natural key" for them to be correctly managed by Parent. However, if Parent is always a top-level object (ie it's never the inverse side of any association), is there anything wrong with using only id?
Are there any unwanted effects that could manifest themselves by doing this? I am guessing that maybe if I do this, that when I add a child (or remove), Hibernate won't be able to tell that Parent has changed (and needs to be updated in DB)? In this case, should I use the children property for Parent.equals() and Parent.hashCode()?
I am asking because the Hibernate docs explicity say not to use the @Id property for a "natural key"...