[hibernate-issues] [Hibernate-JIRA] Resolved: (EJB-375) getSingleResult potentially generates out of memory by calling list()

Emmanuel Bernard (JIRA) noreply at atlassian.com
Thu Aug 14 15:07:06 EDT 2008


     [ http://opensource.atlassian.com/projects/hibernate/browse/EJB-375?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Bernard resolved EJB-375.
----------------------------------

         Assignee: Emmanuel Bernard
       Resolution: Fixed
    Fix Version/s: 3.4

Good catch. BTW you fix should be

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


> getSingleResult potentially generates out of memory by calling list()
> ---------------------------------------------------------------------
>
>                 Key: EJB-375
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-375
>             Project: Hibernate Entity Manager
>          Issue Type: Bug
>          Components: EntityManager
>    Affects Versions: 3.3.2.GA
>         Environment: any
>            Reporter: Pascal P. Pochet
>            Assignee: Emmanuel Bernard
>             Fix For: 3.4
>
>
> 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...)
> easy to circumvent by changing
> 			List result = query.list();
> to
> 			List result = query.setMaxResults(2).list();
> (so we keep the functionality of alerting developer when query is wrongly returning multiple results when it should not...)
> and
> 					em.throwPersistenceException( new NonUniqueResultException( "result returns " + uniqueResult.size() + " elements") );
> to
> 					em.throwPersistenceException( new NonUniqueResultException( "result returns more than 1 element") );

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