Differences among save, update, saveOrUpdate, merge methods in Session?

后端 未结 7 2405
粉色の甜心
粉色の甜心 2020-12-04 08:50

I am new to Hibernate and went through the Hibernate tutorial last week. I have a few doubts about methods save, update, saveOrUpdate and merge in the Session class. These a

7条回答
  •  有刺的猬
    2020-12-04 09:43

    Merge Does Following

    Merge has intelligence. It has lot of pre-checks before it go actual merge(if required)

    1. if Object is transient, It simply fires INSERT query makes object persistent(attached to session)
    2. if Object is detached, fires select query to check whether data modified or not if modified, fires UPDATE query otherwise just ignore merge task.

    where as session.update

    1. throws exception if object is transient.
    2. if Object is detached, it simply fires UPDATE query irrespective of data changes to object.

    session.merge is expensive than update

提交回复
热议问题