title: How to check if entity in Hibernate is dirty?
body: <p>How to check if entity in Hibernate is in dirty state? I.e. I want do set <code>UpdatedBy</code> and <code>UpdatedAt</code> only if some field has changed. So I can do object check manually comparing each field in 2 objects, but may be there exist some more elegant way to do it? </p>
  
  <p>Also, does hibernate makes entity <code>dirty</code> if I set to object's field same value as it was before? I.e.:</p>
  
  <pre><code>String name = myEntity.getName()
  myEntity.setName(name);
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>But also I have another problem - I have entity with nested collections, so if has changed only element in that collection, then I want to set UpdatedBy only on that collection element, but not on object that owns this collection. I make updates using cascade operations.</p>