Easy learning with example program codes

What is the difference between session.saveorupdate and session.persist in hibernate?



Serializable save(Object object) throws HibernateException
Serializable save(String entityName,
                  Object object)
                  throws HibernateException

Save method is used to store an object into the database. It insert an entry if the identifier doesn’t exist. It will throw error if the identifier already exist.


void update(Object object) throws HibernateException
void update(String entityName,
            Object object)
            throws HibernateException

Update method in the hibernate is used for updating the object using identifier. It will throw an exception if the identifier is missing or doesn’t exist.


void saveOrUpdate(Object object)throws HibernateException
void saveOrUpdate(String entityName,
                  Object object)
                  throws HibernateException

The saveOrUpdate method calls save() or update() method based on the operation. If the identifier exists, it will call update method else the save method will be called.

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


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

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki