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.

Please follow and like us:

Copyright © 2020 CodesJava Protection Status