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

后端 未结 7 2446
粉色の甜心
粉色の甜心 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:25

    You are exactly right in all of your assessments. You get it.

    For your first question, if i recall correctly, save specifically does an insert. So calling save again will result in another row in the db.

    For your second question, update updates an object in the session. So if the object is in the session it will update. If the object is not in the session, you should call merge. I believe calling update for a detached instance will result in an exception.

提交回复
热议问题