[
http://opensource.atlassian.com/projects/hibernate/browse/EJB-375?page=co...
]
Pascal P. Pochet commented on EJB-375:
--------------------------------------
you have setMaxResults() that calls selection.setMaxRows() and selection has getMaxRows()
which is not reflected by the wrapping query,
and by adding a local variable int maxResults you store an information already available
somewhere else...
so at first it's just "aesthetical" (symetry, avoid copy of info, ...)...
note that with your patch [as I understand (am I wrong ?)]
if maxResults is -1 at entry the underlaying selection maxRows will be left to 2...
when it should be reset to null... because the API goes from int to Integer when crossing
query/selection border
other changes may be necessary... (there is no clearMaxRows()/clearMaxResults()
functionality in the API...)
(also a comment about the state of maxResults and the underlaying maxRows in case of
exception would be nice...)
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira