What is difference between Save() and Persist() method






    To answer this   question   required attention as both method act like similar, but
       there   are   some basic  difference . which is discussed below

      Save   Method: --
  1. will return the id/identifier when the object is saved to the database.
  2. will also save when the object is tried to do the same by opening a new session after it is detached.
  3. save() method returns an identifier so that an insert query is executed immediately to get the identifier, no matter if it are inside or outside of a transaction.
  4.  Save()  method  does not through any exception  even  it call  detached  transaction state  .
 Persist  Method -----
  1. will return void when the object is saved to the database.
  2. will throw PersistentObjectException when tried to save the detached object through a new session.
     3. The persist method is called outside of transaction boundaries, it is useful in long-running   conversations with an extended Session context. On the other hand save method is not good in a long-running conversation with an extended Session context.

 4. The persist () method doesn’t guarantee that the identifier value will be assigned to the persistent state immediately, the assignment might happen at flush time.
   
    



What is difference between Save() and Persist() method What is  difference between  Save() and Persist()   method Reviewed by Mukesh Jha on 2:15 AM Rating: 5

No comments:

Add your comment

All Right Reserved To Mukesh Jha.. Theme images by Jason Morrow. Powered by Blogger.