java 在休眠状态下需要足够的关于无状态会话的信息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4384515/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Need enough information about stateless session in hibernate
提问by GuruKulki
Hi I am working on hibernate and need some information about the stateless session. tried to search on google but didnt get that much information. so please need any link or pdf's about stateless session on how, why and when to use it. what are the pros and cons of using it. thanks
嗨,我正在研究 hibernate,需要一些有关无状态会话的信息。试图在谷歌上搜索,但没有得到那么多信息。所以请需要任何关于无状态会话的链接或 pdf 文件,了解如何、为什么和何时使用它。使用它的优点和缺点是什么。谢谢
回答by jpkrohling
There isn't much to say about Stateless Sessions, anyway. Basically, it serves only one purpose: to not cache anything at all.
无论如何,关于无状态会话没什么好说的。基本上,它只有一个目的:根本不缓存任何东西。
In regular sessions, Hibernate maintains a "session-level cache", which is cleared when you close your session, for instance. In some other cases, you can plug a caching mechanism to act as a "second level cache", which is complimentary to this "session-level cache" and can survive even after a session is closed.
在常规会话中,Hibernate 维护一个“会话级缓存”,例如,当您关闭会话时,它会被清除。在其他一些情况下,您可以插入一个缓存机制来充当“二级缓存”,这是对这种“会话级缓存”的补充,即使在会话关闭后也能继续存在。
However, this can be a problem if you are in a batch-operation mode. For instance, it doesn't makes sense to keep any entity in the cache (session-level) if you are just reading an input file and inserting entities in the database. You know you won't need that entity anymore. So, that's where you use the Stateless session.
但是,如果您处于批处理操作模式,这可能是一个问题。例如,如果您只是读取输入文件并在数据库中插入实体,那么将任何实体保留在缓存中(会话级)是没有意义的。你知道你不再需要那个实体了。所以,这就是您使用无状态会话的地方。
There's no change in the API, just changes in the implementation.
API 没有变化,只是实现上的变化。
Take a look at this link. This is all you need to know about Stateless Sessions: http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/batch.html#batch-statelesssession
看看这个链接。这是您需要了解的有关无状态会话的全部信息:http: //docs.jboss.org/hibernate/core/3.6/reference/en-US/html/batch.html#batch-statelesssession
回答by kraftan
The book Java Persistence with Hibernatehas a short, but sufficient section about stateless session in Hibernate. If you do not want to buy a copy of that book just for that information, I found the whole book on slideshare.com; Section 12.2.3, page 539 (page 574 on slideshare.com).
Java Persistence with Hibernate这本书有一个简短但足够的部分介绍 Hibernate 中的无状态会话。如果你不想仅仅为了这些信息而购买那本书的副本,我在 slideshare.com 上找到了整本书;第 12.2.3 节,第 539 页(slideshare.com 上的第 574 页)。