Skip to main content



      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 15:36 Go to next message
Eclipse UserFriend
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] Mon, 28 October 2019 21:50 Go to previous message
Eclipse UserFriend
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: Thu Jul 10 04:42:35 EDT 2025

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

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

Back to the top