CodesJava

Easy learning with example program codes

What is the difference between session save and session persist method in hibernate?


Save():

1. Syntax: public Serializable save(Object object) throws HibernateException.
2. The return type of the save method is java.io.Serializable. It returns the generated Id after saving the record.
3. It can save the changes to the database outside of the transaction. i.e. Save method can be used inside or outside the transaction.
4. Session.save() for a detached object will create a new row in the table.
5. Save method takes more time to execute.

Persist():

1. Syntax: public void persist(Object object) throws HibernateException.
2. It does not returns generated Id after saving. Its return type is void.
3. Persist method can be used only within the transaction.
4. session.persist() for a detached object will throw PersistentObjectException as it is not allowed.
5. Persist method takes less time to execute.

Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki