CodesJava

Easy learning with example program codes

What is the difference between session.save session.saveorupdate and session.persist in 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.

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