fix: premature closing of database streams from JpaTicketRegistry #8214
+162
−83
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a problem in JPA ticket registry, where all the methods using a stream over the database queries would return closed streams, causing an error.:
The problem is caused by a default hibernate session that is created on a lower level, when there is no transaction present. This default session is also closed on the lower level, which causes also the closing of the stream.
It can be observed in logs as follows:
The solution is to wrap the methods in transaction, however, there are methods (
getSessionsFor, .getSessionsWithAttributes,stream) from theJpaTicketRegistrythat further return the stream from the DB. So the opening of the transaction always needs to be pushed up all the way to where the stream is consumed.This was working few months ago, so there must have been an update (probably in hibernate) that has caused this new behaviour, but I have not been able to track it down. Nor, have I been able to find a configuration property that would restore the old behaviour, thus this PR.
See also the added test, which just calls one of the stream methods of
JpaTicketRegistry, this test fails without these changes.