title: Hibernate persist vs save
body: <p>I came across this explanation when I was trying to understand between Hibernate Save and persist:</p>
  
  <blockquote>
    <p>persist() is well defined. It makes a transient instance persistent.
    However, it doesn't guarantee that the identifier value will be
    assigned to the persistent instance immediately, the assignment might
    happen at flush time. The spec doesn't say that, which is the problem
    I have with persist(). </p>
    
    <p>persist() also guarantees that it will not execute an INSERT statement
    if it is called outside of transaction boundaries. This is useful in
    long-running conversations with an extended Session/persistence
    context. </p>
    
    <p>A method like persist() is required. </p>
    
    <p>save() does not guarantee the same, it returns an identifier, and if
    an INSERT has to be executed to get the identifier (e.g. "identity"
    generator, not "sequence"), this INSERT happens immediately, no matter
    if you are inside or outside of a transaction. This is not good in a
    long-running conversation with an extended Session/persistence
    context.</p>
  </blockquote>
  
  <p>Can you please help me in understanding the lines for persist that says:</p>
  
  <blockquote>
    <p>persist() also guarantees that it will not execute an INSERT statement
    if it is called outside of transaction boundaries. This is useful in
    long-running conversations with an extended Session/persistence
    context.</p>
  </blockquote>
  
  <p>What are the transaction boundaries here? and what are the long-running conversations? what is extended Session/persistence context means?</p>
  
  <p>Also for save method:</p>
  
  <blockquote>
    <p>this INSERT happens immediately, no matter if you are inside or
    outside of a transaction. This is not good in a long-running
    conversation with an extended Session/persistence context.</p>
  </blockquote>
  
  <p>I understand that we need not have statements like session.beginTransaction() and session.getTransaction().commt() if we are using save method in my program for saving an object. Please let me know if the statement says the same thing here. So how is this useful in long running conversations?</p>
  
  <p>I am new to hibernate and finding it difficulty to understand the differences, can you please help me in understanding the differences.</p>