中易网

关于hibernate的merge、attachDirty、attachClean方法的应用

答案:2  悬赏:60  
解决时间 2021-03-11 22:54
今天自动生成了hibernate的方法之后发现了这几个方法,从网上查找了一下资料,还是不明白,有哪位大侠可以详细解释一下吗?究竟什么时候用的,好像没怎么用到?
// 关于merge() attachDirty() attachClean()三种方法下面做一个简单的介绍

public CodeDepts merge(Usertable detachedInstance) {
log.debug("merging Usertable instance");
try {
Usertable result = (Usertable) getSession()
.merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}


public void attachDirty(Usertable instance) {
log.debug("attaching dirty Usertable instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}


public void attachClean(Usertable instance) {
log.debug("attaching clean Usertable instance");
try {
getSession().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
最佳答案
老大 你给出的例子中讲得很清楚的
全部回答
** * 将传入的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; } } 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; } } 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; } }
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
不知道为什么 我不喜欢人家问我 你要去哪 你
丽友地址在什么地方,想过去办事
dnf意志碎片在哪里兑换 意志碎片能兑换什么奖
dnf怎么样让武神破招几率更高
一种洗发水每瓶降价6元,原来买2瓶的钱现在可
BAJA音响的性能如何?产地在哪里?
找一本异世大陆的,里边的人能与灵兽合体
苹果服饰旗舰店在什么地方啊,我要过去处理事
怀孕抽香烟,孩子可以要吗
梦到一只大老鼠,想去抓,但一直找不到,后来
泽雅山里山农家乐我想知道这个在什么地方
爱彩人官方网站。
自创文言文包含之 以 其80到100字
我这电脑运行什么系统最流畅?附加:Windows7
灵隐寺里500罗汉殿中的琉璃界是什么意思
推荐资讯
We shouId thank those around us。中文是什
韩国叫申什么的女明星
饰界风财富公司可以做到100%担保吗?
启赋和青智的奶粉哪一个更好
GA-350MS计算器如何计算方差
左安镇人口计划生育服务所我想知道这个在什么
国家对于终身没有孩子的家庭有没有什么优惠政
全新速腾与竞品有哪些优点?
百度云网盘网页版打开后怎么一片空白,看不到
固定资产当月减少当月计提折旧吗
非处的女生还会付出自己的真爱吗
iPhone7充电一会儿就自动断开 再也无法充电
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?