Skip to content

Conversation

@kofzera
Copy link

@kofzera kofzera commented Jan 2, 2026

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:

2025-10-21 15:00:40,244 TRACE [org.hibernate.internal.SessionImpl] [A03740AAFC38] - <Opened Session [2042859d-6ffc-4daa-bbd3-e0c67d4a1fa3] at timestamp: 1761051640244>
2025-10-21 15:00:40,252 TRACE [org.hibernate.sql.results.jdbc.internal.DeferredResultSetAccess] [A03740AAFC38] - <Executing query to retrieve ResultSet : select pjte1_0.id,pjte1_0.attributes,pjte1_0.body,pjte1_0.creation_Time,pjte1_0.ex
piration_Time,pjte1_0.last_Used_Time,pjte1_0.parent_Id,pjte1_0.principal_Id,pjte1_0.service,pjte1_0.type from Cas_Tickets pjte1_0 where pjte1_0.type=? and pjte1_0.principal_Id=?>
2025-10-21 15:00:40,252 DEBUG [org.hibernate.SQL] [A03740AAFC38] - <
   select
       pjte1_0.id,
       pjte1_0.attributes,
       pjte1_0.body,
       pjte1_0.creation_Time,
       pjte1_0.expiration_Time,
       pjte1_0.last_Used_Time,
       pjte1_0.parent_Id,
       pjte1_0.principal_Id,
       pjte1_0.service,
       pjte1_0.type
   from
       Cas_Tickets pjte1_0
   where
       pjte1_0.type=?
       and pjte1_0.principal_Id=?>
2025-10-21 15:00:40,255 TRACE [org.hibernate.internal.SessionImpl] [A03740AAFC38] - <Closing session [2042859d-6ffc-4daa-bbd3-e0c67d4a1fa3]>
2025-10-21 15:00:40,270 DEBUG [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] [A03740AAFC38] - <Error advancing (next) ResultSet position [n/a]>
org.postgresql.util.PSQLException: This ResultSet is closed.

The solution is to wrap the methods in transaction, however, there are methods (getSessionsFor, .getSessionsWithAttributes, stream) from the JpaTicketRegistry that 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.

  • Brief description of changes applied
  • Test cases for all modified changes, where applicable
  • The same pull request targeted at the master branch, if applicable
  • Any documentation on how to configure, test
  • Any possible limitations, side effects, etc
  • Reference any other pull requests that might be related

@kofzera
Copy link
Author

kofzera commented Jan 2, 2026

Reopening of 7914

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants