title: Hibernate PostUpdateEvent getState and getOldState order of values
body: <p>A little backstory. I am working on a java project, using spring data, and i need to log all changes made to all entities and what type of change (event type) it is (eg. INSERT, UPDATE, DELETE) in mongodb, in an automated way. </p>
  
  <p>For this i am using hibernate postEventListeners (PostInsertListener, PostUpdateListener and PostDeleteListener). This was all good, but now a change has been made to the original requirement, and i need to create a few more event types ( for example LOGIN ).
  To create the LOGIN event, without completely altering the existing code, i found that i can just have a simple check, to see if the entity that i'm processing is a User and if the only property that is changed is lastLogin. </p>
  
  <pre><code>if (entity instanceof User) {
              if(updateEvent.getDirtyProperties().length == 1 &amp;&amp; updateEvent.getDirtyProperties()[0] == 8)
                  history.setEventType(HistoryEvent.LOGIN);
  }
  </code></pre>
  
  <p>updateEvent is an instace of PostUpdateEvent, from the onPostUpdate function. </p>
  
  <p>This is working fine, but my current implementation is not ideal. In hibernate, getState() and getOldState() return and Object[] that contains all the properties of the object that is being updated. getDirtyProperties() returns the an array of indexes, indexes of only the properties which are not the same in the getState and getOldState arrays.</p>
  
  <p>The problem that i have is that the Object[] returned by getState and getOldState contains only the values of the properties, and i can't figure out the order that they are in. For now i just hardcoded the index, but this solution is not ideal, because if i add/remove a property from the User class, the index also gets modified, and i have to find out what the new index is and change it. </p>
  
  <p>My question is, what order are the properties in the Object[], or how can i change my code so that the value is not hardcoded? Is there a way to get a pair, of property value instead of getting just an array of values? </p>