管理休眠会话
我正在尝试调试一个存在一些性能问题的网络应用程序。我打开了休眠日志记录,我看到了很多这样的内容:
2010-10-28 10:58:00,423 DEBUG [org.hibernate.impl.SessionImpl] - opened session at timestamp: 5276786198212608
2010-10-28 10:58:01,390 DEBUG [org.hibernate.impl.SessionImpl] - opened session at timestamp: 5276786202173440
2010-10-28 10:58:01,418 DEBUG [org.hibernate.impl.SessionImpl] - opened session at timestamp: 5276786202288128
2010-10-28 10:58:26,181 DEBUG [org.hibernate.impl.SessionImpl] - opened session at timestamp: 5276786303717376
我担心没有关于“关闭会话于”的日志,
我目前正在查看以下内容: http://static.springsource.org/spring/docs/2.5 .x/reference/orm.html 但它没有任何东西能让我对日志感到安心
I am trying to debug a web app that is having some performance issues. i turned on hibernate logging and i am seeing a lot of this:
2010-10-28 10:58:00,423 DEBUG [org.hibernate.impl.SessionImpl] - opened session at timestamp: 5276786198212608
2010-10-28 10:58:01,390 DEBUG [org.hibernate.impl.SessionImpl] - opened session at timestamp: 5276786202173440
2010-10-28 10:58:01,418 DEBUG [org.hibernate.impl.SessionImpl] - opened session at timestamp: 5276786202288128
2010-10-28 10:58:26,181 DEBUG [org.hibernate.impl.SessionImpl] - opened session at timestamp: 5276786303717376
I am concerned that there are no logs about "closed session at"
i am currently look at this:
http://static.springsource.org/spring/docs/2.5.x/reference/orm.html
but it doesnt have anything that will give me a peace of mind about the logs
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 源,该消息似乎是从 SessionImpl.java 。会话关闭时有相应的日志语句(请参阅方法
public Connection close() throws HibernateException
),但该日志记录在TRACE
级别。我对 slf4j 不熟悉,但是来自 这篇文档 看起来TRACE
的级别比DEBUG
更精细。因此,请尝试增加日志记录量(也许增加到ALL
?)并验证会话是否已关闭。Looking at the source, the message seems to be logged from the constructor of SessionImpl.java. There is a corresponding log statement when sessions are closed (see the method
public Connection close() throws HibernateException
), but that is logged atTRACE
level. I am not familiar with slf4j, but from this piece of documentation it looks likeTRACE
is at a finer level thanDEBUG
. So try increasing the amount of logging (maybe toALL
?) and verify if sessions are closed.您如何访问会议?你使用的是spring事务注解吗?
我们在当前的应用程序中使用休眠模板..尽管这显然不再需要。虽然我确实看到了其他休眠初始化调试语句,但不知怎的,我没有看到它作为调试出现。
无论如何,您可能可以获得对会话工厂的引用并调用 sessionFactory.getStatistics().getSessionOpenCount()
您可能必须调用 setStatisticsEnabled(true)
http://docs.jboss.org/hibernate/stable/core/api/org/hibernate/stat/Statistics.html
这至少可以让您了解开放会话的数量,看看它是否持续增加。
根据 binil 的回答,还有一个关于不同日志级别的打开/关闭日志条目的错误报告。
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2425
How are you accessing the sessions? Are you using the spring transaction annotation?
We're using the hibernate template in our current app.. though this is apparently no longer needed. I'm somehow not seeing that come out as debug, though I do see other hibernate initialization debug statements.
Anyhow, you can probably get a reference to the session factory and call sessionFactory.getStatistics().getSessionOpenCount()
You might have to call setStatisticsEnabled(true)
http://docs.jboss.org/hibernate/stable/core/api/org/hibernate/stat/Statistics.html
That would at least get you the number of open sessions to see if it is continually going up.
Per binil's answer, there is also a bug report about the opening/closing log entries at different log levels.
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2425