Close deferred query sessions after getResultCount
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 58/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Java
- Stelle
- 60.3k
- Fork
- 38.7k
- Merge medio
- 1g 8h
- PR unite (30g)
- 36
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di spring-projects/spring-framework
-
`YamlProcessor.getFlattenedMap` with `includeEmpty` returns a `null` key for an empty root mappingForse già presa @erfannvb l’ha presa 6 giorni fa. Apertastatus: waiting-for-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
spring-projects/spring-framework#37522 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
`WebClient` with default codecs drops `ProblemDetail` extension membersForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertastatus: waiting-for-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
spring-projects/spring-framework#37503 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
StandardApiVersionDeprecationHandler generates nonconforming Sunset HTTP datesForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertastatus: waiting-for-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
spring-projects/spring-framework#37486 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
FastByteArrayOutputStream input stream rejects valid skip(long) argumentsForse di nuovo libera @hickey-ai l’ha presa 10 giorni fa e non c’è nessuna pull request aperta. Apertastatus: waiting-for-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
spring-projects/spring-framework#37471 · 6 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
LinkedCaseInsensitiveMap.keySet().remove returns false after removing a null-valued entryForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertastatus: waiting-for-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
spring-projects/spring-framework#37470 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di spring-projects/spring-framework
Issue simili
-
Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
protobuf
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
FasterXML/jackson-dataformats-binary#874 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
-
Add the AI-disclosure footer to README.mdForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
-
Add the AI-disclosure footer to README.mdForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
HexaHexes/infinite-dungeon-spawn-safety#17 ·
I maintainer di solito rispondono entro 1 giorno