title: Differences among save, update, saveOrUpdate, merge methods in Session?
body: <p>I am new to Hibernate and went through the Hibernate tutorial last week. I have a few doubts about methods save, update, saveOrUpdate and merge in the Session class. These are:</p>
  
  <ul>
  <li><p><strong>save method:</strong> it is used to insert the newly created object in the datastore. (Basically identifier value will be 0 for this). Like I create a new customer and call save operation, it will persist it in the datastore and generate the identifier. </p>
  
  <p>Is this correct? And if we call save on already persistent object not sure what will happen?</p></li>
  <li><p><strong>update method:</strong> it is used to update the already persistent object in the datastore.(Basically identifier value will be some non zero value for this). Like I load a new customer and call update operation after update of some field value, it will update it in datastore.</p>
  
  <p>As per my understanding it should fail with some exception because as per API update is for detached object. Is this correct? If yes, what should we call to update the object in the same session (I mean if object is not detached). Another point is: what will happen if  we call update on newly created object?</p></li>
  <li><p><strong>saveOrUpdate method:</strong> it will call either of above based on unsaved-value checks (which it must be doing based on identifier zero or non zero value, right?) so if we have persistent customer object and we update last name of his and create a new account also, then saveOrUpdate will take care of it.</p>
  
  <p>Did I understand that correctly?</p></li>
  <li><p><strong>Merge method:</strong>  it will act like update but here if a persistent object with the same identifier is already in the session it will update the detached object values in the persistent object and save it. </p>
  
  <p>But if there is no persistent instance currently associated with the session, this will load the persistent object from the datastore and then update the value of detached object in loaded persistent object and then update it.</p>
  
  <p>Did I also get that?</p></li>
  </ul>