Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Close deferred query sessions after getResultCount

オープン
#37,587 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
58/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java, spring, spring-boot

調査の方向性

Start with SharedEntityManagerCreator.queryTerminatingMethods and inspect how shared EntityManager calls close temporary sessions outside a Spring transaction. Reproduce the lifecycle imbalance with a deferred query's getResultCount(), including the shared EntityManager and EntityAgent paths; verify session closure after success and failure. Done means regression tests cover both proxies and :spring-orm:check passes.

索引モデルが issue の本文から書いたものです。

説明

status: waiting-for-triage

Calling getResultCount() on a deferred query obtained from a shared EntityManager outside a Spring transaction leaves the temporary EntityManager open. The same occurs through the shared JPA 4.0 EntityAgent proxy.

Versions reproduced: Spring Framework 7.1.0-RC1, Hibernate ORM 8.0.0.Beta3, Jakarta Persistence 4.0.0-M7, PostgreSQL 18.6. The relevant code is unchanged on main at 7bdf9c86f8657029567067051b7c6bd47b4ae67e.

With Hibernate statistics enabled and a populated test entity:

EntityManager shared = SharedEntityManagerCreator.createSharedEntityManager(emf);
Statistics statistics = emf.unwrap(SessionFactory.class).getStatistics();
long opened = statistics.getSessionOpenCount();
long closed = statistics.getSessionCloseCount();

long count = shared.createQuery("from TestEntity", TestEntity.class).getResultCount();

System.out.println(statistics.getSessionOpenCount() - opened); // 1
System.out.println(statistics.getSessionCloseCount() - closed); // 0

There is no active Spring transaction in this example. A getResultList() call instead produces one opened and one closed session. Replacing shared with the injected EntityAgent produces the same count-query result and lifecycle imbalance. Inside a Spring transaction, normal transaction cleanup closes the session.

SharedEntityManagerCreator.queryTerminatingMethods includes the list/single-result methods but does not include getResultCount(), now exposed by JPA 4.0 TypedQuery. The existing Hibernate SelectionQuery.getResultCount() entry point is affected as well.

I verified that recognizing getResultCount as a terminating method closes the temporary session for both the shared EntityManager and EntityAgent, including when the count operation throws. Two regression tests fail on the unmodified source because EntityManager.close() is never invoked, and pass with the change. The full :spring-orm:check passes with the change: 369 tests, zero failures, two skipped, including Checkstyle and architecture checks.

This was found while testing the optional Hibernate 8/JPA 4 integration described in #36025.

主要言語
Java
スター
60.3k
フォーク
38.7k
平均マージ
1日 8時間
マージ済み PR(30日)
35

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

spring-projects/spring-framework のほかの issue

spring-projects/spring-framework の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。