在Hibernate中persist()vs save()的优点是什么? [英] What's the advantage of persist() vs save() in Hibernate?
问题描述
任何人都可以告诉我Hibernate中 persist()
vs save()
的优点吗?
From 此论坛帖子
$ b
persist() code>定义明确。它使
的瞬态实例持久化。
但是,它不能保证
标识符值将立即分配给
持久实例,
分配可能发生在
刷新时间。该规范没有说明,
是我用persist()
所遇到的问题。
persist()
还保证
不会执行INSERT语句,如果
在事务
边界之外被调用。这对于
长时间运行的会话和
扩展会话/持久性上下文非常有用。
像
persist()
这样的方法是必需的。
save()
不保证相同,它
返回一个标识符,如果$必须执行b $ b INSERT才能获得
标识符(例如identity生成器,
不是sequence),这个INSERT将立即发生
,无论您是
交易内部或外部。
这对长时间运行的
对话来说不是很好,它具有一个扩展
会话/持久化上下文。
Can anyone tell me what's the advantage of persist()
vs save()
in Hibernate?
From this forum post
persist()
is well defined. It makes a transient instance persistent. However, it doesn't guarantee that the identifier value will be assigned to the persistent instance immediately, the assignment might happen at flush time. The spec doesn't say that, which is the problem I have withpersist()
.
persist()
also guarantees that it will not execute an INSERT statement if it is called outside of transaction boundaries. This is useful in long-running conversations with an extended Session/persistence context.A method like
persist()
is required.
save()
does not guarantee the same, it returns an identifier, and if an INSERT has to be executed to get the identifier (e.g. "identity" generator, not "sequence"), this INSERT happens immediately, no matter if you are inside or outside of a transaction. This is not good in a long-running conversation with an extended Session/persistence context.
这篇关于在Hibernate中persist()vs save()的优点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!