getHibernateTemplate()。update和getHibernateTemplate()。merge之间的区别是什么? [英] What is the difference between getHibernateTemplate().update and getHibernateTemplate().merge

查看:563
本文介绍了getHibernateTemplate()。update和getHibernateTemplate()。merge之间的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理Web项目,在其中我想将用户更新到数据库中。
在编写代码时,我发现如果用作
$ b

I am working on web project in which i want to update user into the database. While writing code I found that it was giving an error if used as


getHibernateTemplate()。update(user)非法尝试将一个集合关联到两个打开的会话;

getHibernateTemplate().update(user) that "Illegal attempt to associate a collection with two open sessions;"

但是,如果我使用 getHibernateTemplate ).merge(user); 它可以很好地工作。
这两者有什么区别?开放会话意味着什么?

But if I tried the same using getHibernateTemplate().merge(user); it perfectly worked fine. What is the difference between those two ? And what exactly means by open session ?

推荐答案

合并可以在会话中使用,而更新仅适用于同一会话。

Merge can work across sessions whereas update works only for the same session.

尽管两者都用于将处于分离状态的对象转换为持久状态,但只有当我们在同一个会话中,更新才会有效,但即使其会话不同,合并也会起作用。

Although both are used for converting the object which is into its detached state to convert the object into its persisted state, but update will work only if we are in the same session, but merge will work even if its different session.

更多 info

通过公开会话,这意味着您目前正在同一会话中执行操作(即在关闭会话之前)。

By open session, it means that you are currently performing the operations in the same session (i.e. before closing the session)

这篇关于getHibernateTemplate()。update和getHibernateTemplate()。merge之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆