[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-4808) SessionImpl.initializeCollection() does not release JDBC connection (if outside of a transaction)
Martin Renner (JIRA)
noreply at atlassian.com
Fri Jan 15 10:23:29 EST 2010
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-4808?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=35241#action_35241 ]
Martin Renner commented on HHH-4808:
------------------------------------
The attached program shows the following output:
{code}
INFO [Test ] Accessing lazily loaded collection...
DEBUG [ConnectionManager ] opening JDBC connection
DEBUG [SQL ] select person0_.id as id0_0_, person0_.version as version0_0_, person0_.name as name0_0_ from Person pe...
DEBUG [SQL ] select pets0_.Person_Id as Person1_1_, pets0_.Pet_Id as Pet2_1_, pet1_.id as id2_0_, pet1_.version ...
INFO [Test ] ...done with collection. Should have seen "aggressively releasing JDBC connection".
INFO [Test ]
INFO [Test ] Executing a query...
DEBUG [SQL ] select person0_.id as id0_, person0_.version as version0_, person0_.name as name0_ from Person person0_
DEBUG [ConnectionManager ] aggressively releasing JDBC connection
DEBUG [ConnectionManager ] releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
INFO [Test ] ...done with query. Should have seen "aggressively releasing JDBC connection".
INFO [Test ]
DEBUG [ConnectionManager ] connection already null in cleanup : no action
{code}
As you can see, the loading of the collection does not release the collection. In contrast, the query does release the connection.
> SessionImpl.initializeCollection() does not release JDBC connection (if outside of a transaction)
> -------------------------------------------------------------------------------------------------
>
> Key: HHH-4808
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4808
> Project: Hibernate Core
> Issue Type: Bug
> Components: core
> Affects Versions: 3.2.7, 3.3.2
> Reporter: Martin Renner
> Priority: Critical
> Attachments: Test.java
>
>
> With {{ConnectionReleaseMode.AFTER_TRANSACTION}} (the default), Hibernate does not release the JDBC connection when resolving a lazily loaded collection, if this happens *outside* of an active transaction.
> First, I will describe, what happens if Hibernate executes a query outside of a transaction. Then I will describe how lazy collection loading behaves differently.
> When the method {{list}} of a query ({{QueryImpl.java}}) is getting called, Hibernate delegates to {{SessionImpl.list()}}. After having loaded the list, {{SessionImpl.list()}} calls {{SessionImpl.afterOperation()}}, which calls {{jdbcContext.afterNontransactionalQuery()}} (as there is no active transaction). This leads to {{ConnectionManager.afterTransaction()}} which releases the JDBC connection. This is exactly what I expect to happen.
> Now to the lazily loaded collection:
> {{Hibernate.initialize(collection)}} and {{person.getPets().size()}} both end up in {{SessionImpl.initializeCollection()}}. This call gets dispatched down to {{Loader.doQueryAndInitializeNonLazyCollections()}} and {{Loader.doQuery()}}. The important fact is, that {{ConnectionManager.afterTransaction()}} never gets called (like in the query-example above).
> The result is, that the JDBC connection is not released.
> IMHO resolving of a lazily loaded collection should behave like executing a query. {{SessionImpl.initializeCollection()}} should call {{SessionImpl.afterOperation()}} in the same way as {{SessionImpl.list()}} is doing this.
> I will attach a small demo application which shows the difference (concerning {{ConnectionManager}}) between queries and collections.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list