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

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


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

Emmanuel Bernard commented on EJB-375:
--------------------------------------

selection is not a public API and is used by the Hibernate Engine, hence the getter. My question was, what real advantages does it give to have this getter for an application using Hibernate. EntityManager is not a "valid" application :)

Thanks for pointing out the flaw, I have fixed it but now I relly on AbstractQueryImpl casting :(




> 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