I am reading about HibernateTemplate class in Spring3.
Here i saw two methods update and saveOrUpdate , i read it from the documentation such as
- update
Update the given persistent instance, associating it with the current Hibernate Session.
Here what is meaning of “associating it with the current Hibernate Session”?
- saveOrUpdate
Save or update the given persistent instance, according to its id (matching the configured “unsaved-value”?). Associates the instance with the current Hibernate Session.
Here what is meaning of “according to its id (matching the configured “unsaved-value”?). Associates the instance with the current Hibernate Session” ?
Please help me
Thanks in advance
Simple – If the object with the same ID exists in the DB , it updates it else if the ID (primary key) is null, it saves it as a new value – Hence saveOrUpdate – depending on whether it’s a value existing in DB or a new value.
The ID match happens by matching your pojo ID in the hbm under the tag with the column specified .
saveOrUpdate() does the following:
From here
Hope this helps.