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
@OneToMany(mappedBy="department")
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
employees.size();


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: 1339
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: Wed Feb 26 01:39:09 GMT 2020

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

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

Back to the top