SpringHibernate显示了大量的空会话

SpringHibernate显示了大量的空会话,spring,hibernate,spring-data,Spring,Hibernate,Spring Data,我正在使用Hibernate5和SpringAPI。使用ApacheTomcat9运行Java8。Mysql 5.x 我使用getSession().getCurrentSession()访问对象,并且每个请求只有一个spring会话。(很高兴粘贴我的struts操作,但不确定是否有帮助) 我启用了stat日志记录,并在最后显示所有查询和会话统计信息。 因此,我会看到一堆查询,然后是(正确的)一个会话摘要: 2017-06-17 19:04:56,621 INFO org.hibernate.

我正在使用Hibernate5和SpringAPI。使用ApacheTomcat9运行Java8。Mysql 5.x 我使用getSession().getCurrentSession()访问对象,并且每个请求只有一个spring会话。(很高兴粘贴我的struts操作,但不确定是否有帮助)

我启用了stat日志记录,并在最后显示所有查询和会话统计信息。
因此,我会看到一堆查询,然后是(正确的)一个会话摘要:

2017-06-17 19:04:56,621 INFO  org.hibernate.engine.internal.StatisticalLoggingSessionEventListener.end - Session Metrics {
    1591683 nanoseconds spent acquiring 9 JDBC connections;
    1073951 nanoseconds spent releasing 8 JDBC connections;
    1173965 nanoseconds spent preparing 10 JDBC statements;
    6098889 nanoseconds spent executing 10 JDBC statements;
    0 nanoseconds spent executing 0 JDBC batches;
    0 nanoseconds spent performing 0 L2C puts;
    0 nanoseconds spent performing 0 L2C hits;
    0 nanoseconds spent performing 0 L2C misses;
    100987632 nanoseconds spent executing 7 flushes (flushing a total of 413 entities and 1445 collections);
    95887194 nanoseconds spent executing 3 partial-flushes (flushing a total of 130 entities and 130 collections)
}
但是,在此(会话结束)之后,它还会显示大约20-40个空会话,如下所示:

2017-06-17 19:04:56,873 INFO  org.hibernate.engine.internal.StatisticalLoggingSessionEventListener.end - Session Metrics {
    0 nanoseconds spent acquiring 0 JDBC connections;
    0 nanoseconds spent releasing 0 JDBC connections;
    0 nanoseconds spent preparing 0 JDBC statements;
    0 nanoseconds spent executing 0 JDBC statements;
    0 nanoseconds spent executing 0 JDBC batches;
    0 nanoseconds spent performing 0 L2C puts;
    0 nanoseconds spent performing 0 L2C hits;
    0 nanoseconds spent performing 0 L2C misses;
    0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections);
    0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0 entities and 0 collections)
}

有人知道这是否正常吗

我对Hibernate不是很熟悉,但会话通常有一个过期时间(通常默认为30或60分钟)。除非在完成会话时显式使其过期,否则它将一直处于活动状态,直到过期时间结束。这看起来很正常,你可能不需要担心。谢谢!非常感谢你的评论。这让我感觉好多了!hahaPlease发布hibernate spring配置部分(sessionFactory和最终的spring过滤器和事务管理器配置)