开发者

Where can I find documentation for NHibernate ISession.Persist()?

开发者 https://www.devze.com 2023-02-05 16:57 出处:网络
NHibernate\'s ISession exposes a method Persist() with two overloads. I cannot find documentation on this method anywhere. It\'s not even mentioned in the NHibernate reference material on http://nhibe

NHibernate's ISession exposes a method Persist() with two overloads. I cannot find documentation on this method anywhere. It's not even mentioned in the NHibernate reference material on http://nhibernate.info/doc/nh/en/index.html.

Is this method deprecated, or will it be? When is it supposed to be u开发者_如何学Csed? How does it compare to SaveOrUpdate()?

Any pointers would be much appreciated.


The last comment on this thread http://opensource.atlassian.com/projects/hibernate/browse/HHH-1273 specifies it very well:

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.

Also it seems from what I could gather from other sources that an entity having cascade="persist" will cascade at the time of the call, not on flush. That might very useful too.

0

精彩评论

暂无评论...
验证码 换一张
取 消