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 Hibernate's Query.scroll() in SharedEntityManagerCreator's queryTerminatingMethods set #31682

Closed
soosue opened this issue Nov 25, 2023 · 2 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: bug A general bug
Milestone

Comments

@soosue
Copy link

soosue commented Nov 25, 2023

Similar to the issue #29886

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

image

Would it be possible to add scroll?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 25, 2023
@sbrannen sbrannen added the in: data Issues in data modules (jdbc, orm, oxm, tx) label Nov 25, 2023
@sbrannen sbrannen self-assigned this Nov 25, 2023
@sbrannen sbrannen changed the title Hibernate Query.scroll() is not included in SharedEntityManagerCreator's queryTerminatingMethods set, causing DB connection not to be released when query is proxied Include Hibernate's Query.scroll() in SharedEntityManagerCreator's queryTerminatingMethods set Nov 25, 2023
@sbrannen sbrannen added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 25, 2023
@sbrannen sbrannen added this to the 6.1.2 milestone Nov 25, 2023
@github-actions github-actions bot added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-6.0.x labels Nov 25, 2023
@sbrannen
Copy link
Member

Hi @soosue,

Congratulations on reporting your first issue for Spring Framework! 👍

Would it be possible to add scroll?

Yes. We'll add that support in 6.1.x and backport it to 6.0.x and 5.3.x.

sbrannen added a commit that referenced this issue Nov 26, 2023
This commit supports the scroll() and scroll(ScrollMode) methods from
Hibernate's Query API in SharedEntityManagerCreator's query-terminating
methods set.

See gh-31682
Closes gh-31683

(cherry picked from commit a15f472)
sbrannen added a commit that referenced this issue Nov 26, 2023
This commit supports the scroll() and scroll(ScrollMode) methods from
Hibernate's Query API in SharedEntityManagerCreator's query-terminating
methods set.

See gh-31682
Closes gh-31684
@jhoeller
Copy link
Contributor

jhoeller commented Nov 30, 2023

Since the detection of scroll is primarily there for preventing accidental Connection leaks (like our existing detection of stream), with the scroll operation not actually working properly outside of a transaction, this should be rather marked as a bug. Query termination is a defensive measure that immediately closes the underlying EntityManager/Connection outside of a transaction.

Only the immediate result operations actually work outside of a transaction, whereas stream or scroll seem to iterate fine at first but eventually leak the Connection, when they really need to operate within a transaction boundary. Only ever use stream and scroll within a transaction (which may be marked as read-only but needs to be managed).

In any case, this closes the gap with our 5.3-intended detection of Hibernate query termination methods, with all such methods treated consistently now.

@jhoeller jhoeller added type: bug A general bug and removed type: enhancement A general enhancement labels Nov 30, 2023
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: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants