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

Avoid explicit flush when handling persistent sessions #29818

Closed
ahus1 opened this issue May 23, 2024 · 0 comments · Fixed by #29819
Closed

Avoid explicit flush when handling persistent sessions #29818

ahus1 opened this issue May 23, 2024 · 0 comments · Fixed by #29819
Assignees
Labels
kind/enhancement Categorizes a PR related to an enhancement release/25.0.0 team/sre

Comments

@ahus1
Copy link
Contributor

ahus1 commented May 23, 2024

Description

Looking at JpaUserSessionPersisterProvider, there are several explicit em.flush() statements which hurt performance.

Discussion

No response

Motivation

Since Hibernate 5.2 which was published after the code in question was written, Hibernate changed its behavior to automatically flush before a query, see https://vladmihalcea.com/how-do-jpa-and-hibernate-define-the-auto-flush-mode/

Due to this, it is OK not to flush explictly, and all changes will be in the database before any future delete or select is triggered in the same transaction.

It could be a change in semantics that a conflict of entries becomes visible only once the transaction is committed.

Still, the old code only caught situations where another transaction has already committed that entry, and situations where concurrent transactions occur can still happen, so removing em.flush() shouldn't break anything that wasn't already broken before.

Details

This should not be affected by the orphan removal problem seen in https://hibernate.atlassian.net/browse/HHH-15230

@ahus1 ahus1 added kind/enhancement Categorizes a PR related to an enhancement team/sre labels May 23, 2024
@ahus1 ahus1 self-assigned this May 23, 2024
ahus1 added a commit to ahus1/keycloak that referenced this issue May 23, 2024
Closes keycloak#29818

Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
mhajas pushed a commit that referenced this issue May 28, 2024
Closes #29818

Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Categorizes a PR related to an enhancement release/25.0.0 team/sre
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant