title: Hibernate DefaultSaveOrUpdateEventListener checking for insert and update database events
body: <p>Using hibernate 3.3.2.ga and Spring 3.0.5.RELEASE.</p>
  
  <p>Have implemented something as described <a href="http://notatube.blogspot.com/2010/03/hibernate-using-event-listener-to-set.html" rel="nofollow">here</a>..</p>
  
  <p>with a different config as I;m using a Spring managed sessionFactory</p>
  
  <pre><code>&lt;bean id="sessionFactoryPGAD" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSourcePGAD"/&gt;
  .......
  .......
  &lt;property name="eventListeners"&gt;
      &lt;map&gt;
          &lt;entry key="save-update"&gt;&lt;ref local="auditEntityListener" /&gt;&lt;/entry&gt;
      &lt;/map&gt;
  &lt;/property&gt;
  </code></pre>
  
  <p></p>
  
  <p>to add auditing when my DAOs call </p>
  
  <pre><code>...getCurrentSession().saveOrUpdate(...
  </code></pre>
  
  <p>However in my extended DefaultSaveOrUpdateEventListener (bean named auditEntityListener) I was wondering if there is any way to determine if the object being saved to the db is a new record or an update to one that exists?</p>
  
  <p>I've tried looking at </p>
  
  <pre><code>EntityEntry entityEntry = event.getEntry();
  if (entityEntry.isExistsInDatabase())
  {.....
  </code></pre>
  
  <p>but entityEntry is null for an entity I know exists in the db.</p>
  
  <p>Other methods on SaveOrUpdateEvent like getRequestedId() and getResultId() also return null.</p>
  
  <p>How could I determine if the hibernate call will be a insert or update from the DefaultSaveOrUpdateEventListener?</p>