title: Hibernate detecting if an object is transient with concurrent persistence
body: <p>I need to detect if an object is transient..if it is not I want to update via Hibernate.</p>
  
  <p>Usually I do this by checking if the id has been set but I am worried this is not thread safe and I  have another thread which is saving the object and its possible that the id is not set but the Hibernate is already in the process of saving the object.</p>
  
  <p>How can I do this in a thread-safe way?</p>
  
  <p>Thanks.</p>
  
  <pre><code>public void updateIfNotNew(PersistentObject a){
  //if another object is in the process of saving....this update will not get persisted
      if (a.id!=null){  
          session.update(a);
       }
  }
  </code></pre>