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

Pascal P. Pochet (JIRA) noreply at atlassian.com
Thu Aug 14 05:11:06 EDT 2008


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


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