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()

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

--- James Sutherland
 EclipseLink ,
Wiki: EclipseLink , TopLink 
Forums: TopLink , EclipseLink 
Book: Java Persistence 
View this message in context:
Sent from the EclipseLink - Users mailing list archive at

Back to the top