Hibernate version:
3.2 and 3.3
Hi everyone.
Here is my use case: I have a method with multiple hibernate reads (mostly getById type of reads). Execution of this method is happening outside of the transaction or in other words transaction was not started prior to the series of the "getById" calls.
For all getById calls I can see that connection is obtained from the pool and then released right after statement is done. And this behavior is fine and is what I want. The surprise comes when lazy collection is loaded. I can see that connection was taken, SQL query to load collection is completed, but connection is not released. Connection will be held until either session.close() or until the end of another getById call (or probably until some other event which aggressively releases connection) .
I have hibernate's connection release mode set to "after_transaction". This works just fine and if transaction is started prior to all read operations one connection is used for all of them and then connection is released at the end of the transaction. Again this is perfect and what I need/expect when I explicitly start transaction and need all reads in one transaction.
So I guess the problem is only with lazy collections loaded outside of the transaction. That’s when the connection release behavior is unpredictable.
Is this expected or is this a bug?
In short the behavior that I want to achieve is in the case transaction is not started I want all reads be made with "after_statement" connection release semantic and only if transaction is started then "after_transaction" semantic be applied. For simplicity sake let’s assume that I only have reads (no writes whatsoever).
Thanks a lot for attention.
-Nick
|