title: How does Hibernate detect dirty state of an entity object?
body: <p>Is it using some kind of byte codes modification to the original classes?</p>
  <p>Or, maybe Hibernate get the dirty state by compare the given object with previously persisted version?</p>
  <p>I'm having a problem with <code>hashCode()</code> and <code>equals()</code> methods for complicated objects. I feel it would be very slow to compute hash code if the object has collection members, and cyclic references are also a problem.</p>
  <p>If Hibernate won't use <code>hashCode()</code>/<code>equals()</code> to check the dirty state, I guess I should not use <code>equals()</code>/<code>hashCode()</code> for the entity object (not value object), but I'm also afraid if the same operator (<code>==</code>) is not enough.</p>
  <p>So, the questions are:</p>
  <ol>
  <li><p>How does Hibernate know if a property of an object is changed?</p>
  </li>
  <li><p>Do you suggest to override the <code>hashCode()</code>/<code>equals()</code> methods for complicated objects? What if they contains cyclic references?</p>
  <p>And, also,</p>
  </li>
  <li><p>Would <code>hashCode()</code>/<code>equals()</code> with only the <code>id</code> field be enough?</p>
  </li>
  </ol>