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

Emmanuel Bernard (JIRA) noreply at atlassian.com
Fri Aug 15 11:17:06 EDT 2008


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

Emmanuel Bernard commented on HHH-3432:
---------------------------------------

the patch is broken: if maxResults is never set, we need to set back selection.setMaxResults to null
Note that Hibernate EntityManager cannot do that without casting to AbstractQueryImpl :(
It would be nice to expose some QueryImplementor API to officialize the interface between HEM and Core and allow to reinitialize maxResults



> query.uniqueResult() potentially generates out of memory by calling list()
> --------------------------------------------------------------------------
>
>                 Key: HHH-3432
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3432
>             Project: Hibernate3
>          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