2008-05-20
hibernate persist() vs save()
关键字: java
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 with persist().
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.
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.
发表评论
最近加入圈子
最新评论
-
又一个DynamicDao
呵呵,老大你写的东东,不错。我学习了(刚刚一新手哈!) 不过,要是再写一点注释就 ...
-- by heshencao -
又一个DynamicDao
实现Query Annotation的主要代码如下: public class ...
-- by studyworks -
又一个DynamicDao
Norther 写道 没看出来dynamic在哪?就是自己实现了一套Crite ...
-- by studyworks -
又一个DynamicDao
没看出来dynamic在哪?就是自己实现了一套Criteria,而且Generi ...
-- by Norther







评论排行榜