Skip to main content

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


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,
View this message in context:
Sent from the EclipseLink - Users mailing list archive at

Back to the top