请问hibernate中merge()、attachDirty()、attachClean()这三个方法是做什么的?怎么用?
答案:1 悬赏:0 手机版
解决时间 2021-03-25 21:58
- 提问者网友:蔚蓝的太阳
- 2021-03-25 04:25
请问hibernate中merge()、attachDirty()、attachClean()这三个方法是做什么的?怎么用?
最佳答案
- 五星知识达人网友:笑迎怀羞
- 2021-03-25 05:05
**
* 将传入的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;
}
}
* 将传入的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;
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯