August 2017
Beginner to intermediate
370 pages
8h 37m
English
The saveOrUpdate operation is used for persisting (save or update) both transient and detached instances based on whether data already exists in the database. It results in SQL INSERT or SQL UPDATE. It is recommended to use the saveOrUpdate method within transaction boundaries. The following represents the saveOrUpdate API:
void saveOrUpdate(Object object) throws HibernateException
The code sample represents the use of the saveOrUpdate API for saving data as a result of a new user signup with the HealthApp, or, updating the user profile data for the logged in user:
Session session = this.sessionFactory.openSession(); session.beginTransaction(); session.saveOrUpdate(user); session.getTransaction().commit(); session.close(); ...
Read now
Unlock full access