[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3432) query.uniqueResult() potentially generates out of memory by calling list()

Alexey Stukalov (JIRA) noreply at atlassian.com
Mon Oct 6 06:14:05 EDT 2008


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

Alexey Stukalov commented on HHH-3432:
--------------------------------------

Another issue with this patch: native queries that explicitly set result limits (LIMIT in MySQL) in query text now fail with syntax error.

> query.uniqueResult() potentially generates out of memory by calling list()
> --------------------------------------------------------------------------
>
>                 Key: HHH-3432
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3432
>             Project: Hibernate Core
>          Issue Type: Bug
>    Affects Versions: 3.2.6, 3.3.0.CR2
>            Reporter: Emmanuel Bernard
>
> calling list() while the user expects a single result has potential major flow: it's easy to trigger an out of memory situation where nobody would expect it... 
> like getSingleResult("select CURRENT_TIME from AN_ENTITY_CONTAINING_ZILLIONS_OF_RECORDS") ; 
> (and it is also a performance problem when it doesn't trigger the out of heap space... and a design issue: why fetching something the caller is not asking for ? with all the consequences on the cache...) 
> fix:
> Something like that
> if (maxResults != 1) query.setMaxResults( 2 ); //avoid OOME if the list is huge
> List result = query.list();
> if ( maxResults != -1 ) query.setMaxResults( maxResults ); //put back the original value

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