JPA entity identity and dirty checking
<p>From <a href="https://stackoverflow.com/questions/4725785/stop-hibernate-from-updating-collections-when-they-have-not-changed">this SO answer</a>:</p>

<blockquote>
  <p>The update() method forces an update to the persistent state of the
  object in the database, always scheduling an SQL UPDATE. ... It
  doesn’t matter if the item object is modified before or after it’s
  passed to update(). ... Hibernate always treats the object as dirty
  and schedules an SQL UPDATE., which will be executed during flush. On
  the other hand, merge() queries the database first, and doesn't
  perform update if state haven't changed.</p>
</blockquote>

<p>A doubt emerged in my mind:<br>
How is Hibernate (or any JPA implementation) able to tell if the state of an    entity has changed so that an update operation is needed ?<br>
Should we implement equals or hashcode method to help Hibernate to do so ? 
What if do not implement those methods ?  </p>