gpt4 book ai didi

nhibernate - 在哪里可以找到 NHibernate ISession.Persist() 的文档?

转载 作者:行者123 更新时间:2023-12-04 20:22:39 24 4
gpt4 key购买 nike

NHibernate 的 ISession 公开了一个具有两个重载的方法 Persist()。我在任何地方都找不到有关此方法的文档。在 http://nhibernate.info/doc/nh/en/index.html 上的 NHibernate 引用资料中甚至没有提到它.

这种方法是否已被弃用,还是会被弃用?它应该在什么时候使用?它与 SaveOrUpdate() 相比如何?

任何指针将不胜感激。

最佳答案

此线程的最后一条评论 http://opensource.atlassian.com/projects/hibernate/browse/HHH-1273很好地说明了它:

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.



此外,从我从其他来源收集的信息来看,具有cascade =“persist”的实体将在调用时级联,而不是在刷新时级联。这也可能非常有用。

关于nhibernate - 在哪里可以找到 NHibernate ISession.Persist() 的文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4716698/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com