如何解决Quarkus JPA Hibernate Statistics显示同一事务下正在使用多个连接
我有一个使用quarkus和hibernate访问postgresql数据库的项目。做一些测试,我发现每个请求的休眠统计信息报告每个请求正在使用多个连接。我虽然在同一事务的后台执行的所有查询都将使用相同的物理连接,但是我不确定这是否正在发生。
我已经提供了一个示例here,在这里下载并执行测试将具有相同的行为。该测试将执行并结束在同一事务中执行同一查询四次的端点
基于这段代码:
2020-08-21 16:28:13,079 INFO [org.hib.eng.int.StatisticalLoggingSessionEventListener] (executor-thread-1) Session Metrics {
5371760 nanoseconds spent acquiring 4 JDBC connections;
61585 nanoseconds spent releasing 4 JDBC connections;
18094275 nanoseconds spent preparing 4 JDBC statements;
19146452 nanoseconds spent executing 4 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)
}
有人知道JDBC连接是指向数据库的物理连接,还是仅仅知道实体管理器已请求四次连接到连接池?
谢谢。
解决方法
来自连接池的
4次请求。您所做的每个查询都可以在一个语句中完成,因此您为什么要使用查询作为连接。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。