Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Size of @OneToMany List(Reliable way to know size of @OneToMany List)
Size of @OneToMany List [message #1815951] Tue, 15 October 2019 19:36 Go to next message
JeeDev_User JeeDev_User is currently offline JeeDev_User JeeDev_UserFriend
Messages: 1
Registered: October 2019
Junior Member
Hi all,
A classic example - I have Department entity, in which exist the following association:

//bi-directional many-to-one association to Employee
private List<Employee> employees;

Now, wondering, what is the reliable way to know , how many elements that list contains ? Is it enough to just call

OR i need to perform TypedQuery, ie,

select count(emp) from Employee emp where department =...
Re: Size of @OneToMany List [message #1816396 is a reply to message #1815951] Tue, 29 October 2019 01:50 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hopefully you just tried both.

If you do, you'll find that calling collection.size() is a java operation that runs on the collection. The collection is fetched only once from the Database, so if you plan to use the collection, that might be more efficient then calling a query for the count, and then having to access the collection to fetch it from the database.
Previous Topic:"Bug" with JPA InheritanceType SINGLE_TABLE and key
Next Topic:No Snapshots for 2.6.6, 2.7.4 and2.7.5
Goto Forum:

Current Time: Sat Jul 20 10:11:56 GMT 2024

Powered by FUDForum. Page generated in 0.03937 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top