save vs update vs saveorupdate Hibernate

Save:

Save

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.

Update

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.

saveOrUpdate

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.