问题描述
我只是遵循一个简单的hibernate struts教程,并通过hibernate成功完成了数据库调用。但是,我没有看到代码关闭任何地方的休眠连接。
sessionFactory.getCurrentSession();
用于获取每个请求的会话。我应该在用户注销时关闭此会话吗?或者在每次请求之后,这个东西是否被框架照顾?第二个相关的问题是,在什么样的用例中我会使用hibernate会话拦截器?
和第三个问题(对不起,它只是在我脑海中弹出)用hibernate / struts2缓存的最佳选择是什么?
关于第一个问题,说:
关于第三个问题,Struts2是一个表示框架。它与持久性实体无关并因此缓存持久性实体。 详细介绍了第二级缓存。
正如你所看到的,文档中有很多有趣的信息。我会建议阅读它。
I just followed a simple hibernate struts tutorial and succesfully made db calls through hibernate. However I don't see the code closing the hibernate connection anywhere.
sessionFactory.getCurrentSession();
is used to get the session per request. Should I close this session when the user logs out? or after each request of is this something taken care of by the framework?
a second related question is, In what kind of use case would I use a hibernate session interceptor?
and a third question(sorry it just popped in my mind) what the best option for caching with hibernate/struts2?
Regarding the first question, the reference documentation says:
Regarding your second question, the documentation says:
Regarding the third question, Struts2 is a presentation framework. It has nothing to do with persistence and thus caching of the persistent entities. The documentation talks in details about the second-level cache.
As you see, the documentation has a whole lot of interesting information. I would advise reading it.
这篇关于休眠会话关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!