YCOE

You Can't stOp mE!

导航

Hibernate merge方法

Posted on 2006-12-25 23:52  YCOE  阅读(5418)  评论(3编辑  收藏  举报
Hibernate中的merge方法挺好用的。官方文档的说明如下:

merge
Copy the state of the given object onto the persistent object with the same identifier. If there is no persistent instance currently associated with the session, it will be loaded. Return the persistent instance. If the given instance is unsaved, save a copy of and return it as a newly persistent instance. The given instance does not become associated with the session. This operation cascades to associated instances if the association is mapped with cascade="merge".

The semantics of this method are defined by JSR-220.

Parameters:
object - a detached instance with state to be copied
Returns:
an updated persistent instance
Throws:
HibernateException


  有几种情况:
  1.如果idertifier(以下简称为id)为空或不存在,则进行inert动作
  2.如果id存在,则进行update动作
  至于会话层的就如文档上所说,不再多说。