當前位置:編程學習大全網 - 行動軟體 - 請問hibernate中merge()、attachDirty()、attachClean()這三個方法是做什麽的?怎麽用?

請問hibernate中merge()、attachDirty()、attachClean()這三個方法是做什麽的?怎麽用?

**

* 將傳入的detached狀態的對象的屬性復制到持久化對象中,並返回該持久化對象

* 如果該session中沒有關聯的持久化對象,加載壹個,如果傳入對象未保存,保存壹個副本並作為持久對象返回,傳入對象依然保持detached狀態。

* @see com.CodeDepts

*/

public CodeDepts merge(CodeDepts detachedInstance) {

log.debug("merging CodeDepts instance");

try {

CodeDepts result = (CodeDepts) getSession()

.merge(detachedInstance);

log.debug("merge successful");

return result;

} catch (RuntimeException re) {

log.error("merge failed", re);

throw re;

}

}

/**

* 將傳入的對象持久化並保存。

* 如果對象未保存(Transient狀態),調用save方法保存。如果對象已保存(Detached狀態),調用update方法將對象與Session重新關聯。

* @see com.CodeDepts

*/

public void attachDirty(CodeDepts instance) {

log.debug("attaching dirty CodeDepts instance");

try {

getSession().saveOrUpdate(instance);

log.debug("attach successful");

} catch (RuntimeException re) {

log.error("attach failed", re);

throw re;

}

}

/**

* 將傳入的對象狀態設置為Transient狀態

* @see com.CodeDepts

*/

public void attachClean(CodeDepts instance) {

log.debug("attaching clean CodeDepts instance");

try {

getSession().lock(instance, LockMode.NONE);

log.debug("attach successful");

} catch (RuntimeException re) {

log.error("attach failed", re);

throw re;

}

}

  • 上一篇:索愛K750C
  • 下一篇:業績超預期下滑 中興通訊被指變相裁員
  • copyright 2024編程學習大全網