Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Lazying-loading and Collection.size()

Normally if a collection is too big for you to ever desire loading it, you
should not map it.  Just query it instead.



cowwoc wrote:
> 
> In other words, it will retrieve the entire resultset and dump it into
> memory? Is there a way to perform the following operations efficiently?
> 
> 1) get the size of the collection
> 2) retrieve an element at index X
> 
> all of this without retrieving the entire collection from the database and
> (ideally) without issuing queries explicitly.
> 
> Gili
> 
> 
> James Sutherland wrote:
>> 
>> size() will instantiate lazy collections in EclipseLink and any other JPA
>> implementation that I know of.  I'm not sure the JPA spec says anything
>> about it.
>> 
>> 
>> 
>> cowwoc wrote:
>>> 
>>> Hi,
>>> 
>>> What does the JPA standard (and alternatively EclipseLink) say about
>>> Lazy Loading and Collection/Set/List.size()? If the collection hasn't
>>> been initialized yet, does size() simply invoke a count(*) query or does
>>> it retrieve the entire collection including its elements?
>>> 
>>> I'm thinking of the following use-case:
>>> 
>>> 1) int size = myList.size();
>>> 2) Object randomElement = myList.get((int) (Math.random() * size));
>>> 
>>> What is guaranteed to happen under the hood according to JPA and
>>> according to EclipseLink? Ideally I want to pass a Collection around my
>>> API, instead of forcing it to be Query-aware and issue SQL statements
>>> explicitly.
>>> 
>>> Thank you,
>>> Gili
>>> 
>> 
>> 
> 
> 


-----
---
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://www.nabble.com/Lazying-loading-and-Collection.size%28%29-tp19581000p19629289.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top