title: Hibernate: check which entity's fields are modified
body: <p><em><strong>What I have:</em></strong></p>
  
  <p>I've Hibernate entity, which contains many non-transient fields, including collections. User can update each field separately or some group of fields at once.</p>
  
  <p><em><strong>What a challange:</em></strong></p>
  
  <p>In handler I should check what field of the entity  have been changed:</p>
  
  <pre><code>public void handle(Entity newVersion) {
    Session session = sessionFactory.openSession();
    Entity oldVersion = (Entity) session.get(Entity.class, entity.getId());
    List changedFields = compareChanges(oldVersion, newVersion);  //HOW TO CHECK WHICH FIELDS ARE CHANGED?
  }
  </code></pre>
  
  <p>I want to do it for security and notification reasons. Means:</p>
  
  <ol>
  <li>Not all users can modify all fields</li>
  <li>I should notify specific users in specific ways on some fields change.</li>
  </ol>
  
  <p><em><strong>What a problem:</em></strong></p>
  
  <p>I get very ugly code. Actually I iterate throught all fields/collections and call <code>equals</code> method.</p>
  
  <p><em><strong>Question:</em></strong></p>
  
  <p><em>May be Hibernate provide more elegant way to check what fields have been modified? How?</em></p>
  
  <p><em><strong>P.S.</em></strong></p>
  
  <p>@victorantunes provide a solution, but it seems too comprehensive for me. May be some alternatives?</p>