今天自动生成了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;
}
}
关于hibernate的merge、attachDirty、attachClean方法的应用
答案:2 悬赏:60
解决时间 2021-03-11 22:54
- 提问者网友:她是我的お女人
- 2021-03-11 14:26
最佳答案
- 二级知识专家网友:我们只是兮以城空
- 2021-03-11 15:09
老大 你给出的例子中讲得很清楚的
全部回答
- 1楼网友:留下所有热言
- 2021-03-11 16:08
**
* 将传入的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;
}
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯