[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-1311) Session.load is O(n) when outside a transaction

Nicolas Cohen (JIRA) noreply at atlassian.com
Mon May 11 23:25:13 EDT 2009


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1311?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=33142#action_33142 ] 

Nicolas Cohen commented on HHH-1311:
------------------------------------

We are seeing the same issue with a large object set. 
this gets really slow eventually.
why does it need to iterate through each entry and set the lock mode to NONE?

> Session.load is O(n) when outside a transaction
> -----------------------------------------------
>
>                 Key: HHH-1311
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1311
>             Project: Hibernate Core
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 3.0.5
>            Reporter: Matt Sgarlata
>
> When retrieving objects from the session-level cache, session.load is O(n) when outside a transaction, where n = the number of objects currently contained in the session-level cache.  This is because after each object is retrieved Hibernate iterates through all objects in the session and sets the lock mode to LockMode.NONE.  This means reading all objects from the Hibernate session-level cache while outside a transaction is an O(n^2) operation instead of an O(n) operation.
> If my understanding is correct, all objects in the session should already have that lock mode unless a different lock mode was specifically requested by the user.  Thus iterating through all objects in the session is not necessary in the vast majority of cases.  I think performance could be improved here by maintaining a cache of the objects in the session that are currently locked.  Then performance of session.load would be O(m) where m is the number of objects which are currently locked in the session.  In the vast majority of cases this would effectively make session.load a O(1) operation since objects in the session typically are not locked.
> The other solution for me, of course, would be to just wrap all web requests so that I begin transactions at the start of the request and end transactions at the end of the request.  However, I don't want to do that because transactions require database resources and I feel it's not necessary to incur that overhead on the read-only screens in my application.

-- 
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