推扬网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
推扬网 门户 你问我答 查看内容

林雨欣:请问hibernate中merge()、attachDirty()、attachClean()这三个方法是做什么的 ...

2020-8-12 17:43| 发布者: admin| 查看: 164| 评论: 0

摘要: 周海鸥的回答: ** * 将传入的detached状态的对象的属性复制到持久化对象中,并返回该持久化对象 * 如果该session中没有关联的持久化对象,加载一个,如果传入对象未保存,保存一个副本并作为持久对象返回,传入对象 ...

周海鸥的回答:

** * 将传入的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; } }


鲜花

握手

雷人

路过

鸡蛋

最新评论

热门推荐
最新资讯

广告服务|投稿要求|禁言标准|版权说明|免责声明|手机版|小黑屋|推扬网 ( 粤ICP备18134897号 )|网站地图 | 邮箱:vayae@hotmail.com

GMT+8, 2025-5-1 20:16 , Processed in 0.060709 second(s), 29 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

返回顶部