请教:Hibernate 中的attachDirty,attachClean,merge之间的区别????? 请教:Hibernate 中的attachDirty,attachClean,merge之间的区别?????多谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 merge:将传入的detached状态的对象的属性复制到持久化对象中,并返回该持久化对象 。如果该session中没有关联的持久化对象,加载一个,如果传入对象未保存,保存一个副本并作为持久对象返回,传入对象依然保持detached状态。attachDirty:将传入的对象持久化并保存。如果对象未保存(Transient状态),调用save方法保存。如果对象已保存(Detached状态),调用update方法将对象与Session重新关联。attachClean:将传入的对象状态设置为Transient状态。 // 关于merge() attachDirty() attachClean()三种方法下面做一个简单的介绍 /** * 将传入的detached状态的对象的属性复制到持久化对象中,并返回该持久化对象。 * 如果该session中没有关联的持久化对象,加载一个,如果传入对象未保存,保存一个副本并作为持久对象返回,传入对象依然保持detached状态。 */ 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; } } /** * 将传入的对象持久化并保存。 * 如果对象未保存(Transient状态),调用save方法保存。如果对象已保存(Detached状态),调用update方法将对象与Session重新关联。 */ 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; } } /** * 将传入的对象状态设置为Transient状态 */ 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; } } classpath 路径 一个关于SPRING MVC全局变量的问题. 菜鸟问题,jsp页面上下之间总是空着一块 小区设置物业企业 null与""的区别 路过的高手请进,帮我看看这个问题你们是否曾经遇见过,如何解决--关于spring+hibernate java怎么调用excel的宏? <jsp:setProperty>应该怎么用呀? 非要用TOMCAT吗? mybatis XML web开发用什么编码好?gbk?gb2312?utf-8? tomcat6 打开中文资源的问题
/**
* 将传入的detached状态的对象的属性复制到持久化对象中,并返回该持久化对象。
* 如果该session中没有关联的持久化对象,加载一个,如果传入对象未保存,保存一个副本并作为持久对象返回,传入对象依然保持detached状态。
*/
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;
}
} /**
* 将传入的对象持久化并保存。
* 如果对象未保存(Transient状态),调用save方法保存。如果对象已保存(Detached状态),调用update方法将对象与Session重新关联。
*/
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;
}
} /**
* 将传入的对象状态设置为Transient状态
*/
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;
}
}