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

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


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

Pascal P. Pochet commented on EJB-375:
--------------------------------------

right...

btw

adding
	public Integer getMaxResults();
to org.hibernate.Query.java
with

	public Integer getMaxResults() {
		return selection.getMaxRows() ;
	}

in org.hibernate.impl.AbstractQueryImpl.java

would be a cheap addition...




> 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