I've run across an issue with hibernate's lazy association loading in combination with connection.release_mode="after_transaction".
For our use case we use a hibernate session per conversation pattern to support lazy loading association and deal with ajax calls.
The root of this issue appears to be covered in the following bug report from 2 years ago:
https://hibernate.onjira.com/browse/HHH-4808We use explicit transactions around operations involving writing to the database at the service layer and do not wrap entire web requests in transactions for several reasons. This means that the lazy loading that often happens when the view is rendered is always outside an explicitly defined transaction boundary.
As mentioned in the bug report, regular queries executed outside a transaction do release their connections after the query, it appears to be only lazy loading queries that do not behave this way.
The end result for us is that the connections in the underlying connection pool get exhausted when a lazy load happens but the user doesn't do anything that would result in the explicit closing of the conversation. We have to wait for the conversation timeout to trigger, which closes the session and finally releases the connection.
A simple example case is a page displaying a data table of and entity in rows with basic properties in columns and a detail button that when clicked makes an ajax call to rendered some details about row in a dialog box. Since the details for every row are not generally needed we setup our entities to lazy load those details only when they are needed. As soon as this happens though, we have a hanging connection that will not close until the hibernate session is closed, which depending on user action can easily be 10-15 minutes later when the conversation times out.
Is there a work around for this issue?