Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include all Hibernate query methods in SharedEntityManagerCreator's queryTerminatingMethods set #29886

Closed
mansonng opened this issue Jan 26, 2023 · 3 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Milestone

Comments

@mansonng
Copy link

Similar to the issue #23248

The org.springframework.orm.jpa.SharedEntityManagerCreator.queryTerminatingMethods does not contain the "uniqueResult" method:

SharedEntityManagerCreator#queryTerminatingMethods

When the EntityManager is closed and org.hibernate.query.Query.uniqueResult() is used, as QueryImpl is delegated by DeferredQueryInvocationHandler, the database connection could not be released:

SharedEntityManagerCreator#queryTerminatingMethods-uniqueResult

Seems uniqueResult might not be used here, but add this could prevent this issue as it could not stop developers to use uniqueResult.
Would it be possitble to add uniqueResult?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 26, 2023
@sbrannen sbrannen changed the title Hibernate Query#uniqueResult is not included in SharedEntityManagerCreator#queryTerminatingMethods set, cased database connection leak Hibernate Query#uniqueResult is not included in SharedEntityManagerCreator's queryTerminatingMethods set, causing DB connection leak Jan 26, 2023
@sbrannen sbrannen added in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement labels Jan 26, 2023
@sbrannen
Copy link
Member

Indeed, this is very similar to #23248 and therefore seems like a reasonable enhancement.

Though, if we're going to support Hibernate's list() and uniqueResult() methods, I think we should probably go ahead and support the following as well.

  • uniqueResultOptional()
  • stream()

@jhoeller, thoughts?

@sbrannen sbrannen self-assigned this Jan 26, 2023
@sbrannen sbrannen removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 26, 2023
@sbrannen sbrannen added this to the 6.0.5 milestone Jan 26, 2023
@jhoeller
Copy link
Contributor

Indeed, it does not hurt to aim for complete coverage of Hibernate's query execution methods there. Since the aforementioned methods all seem to be present in Hibernate ORM 5.6 already, we should also backport this to Spring Framework 5.3.26.

@sbrannen sbrannen added the for: backport-to-5.3.x Marks an issue as a candidate for backport to 5.3.x label Jan 26, 2023
@github-actions github-actions bot added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.3.x Marks an issue as a candidate for backport to 5.3.x labels Jan 26, 2023
@sbrannen sbrannen changed the title Hibernate Query#uniqueResult is not included in SharedEntityManagerCreator's queryTerminatingMethods set, causing DB connection leak Include all Hibernate query methods in SharedEntityManagerCreator's queryTerminatingMethods set Jan 27, 2023
@sbrannen
Copy link
Member

This has been addressed as described in commit 57fb072 for inclusion in 6.0.5 and backported to 5.3.26 in commit 3d6d853.

mdeinum pushed a commit to mdeinum/spring-framework that referenced this issue Jun 29, 2023
…rminatingMethods

Prior to this commit, we included Hibernate's Query.list() method in
SharedEntityManagerCreator's queryTerminatingMethods set but did not
include all of Hibernate's query-terminating methods.

To address this, this commit additionally includes the stream(),
uniqueResult(), and uniqueResultOptional() methods from Hibernate's
Query API in SharedEntityManagerCreator's query-terminating methods set.

Closes spring-projectsgh-29886
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants