Size of @OneToMany List [message #1815951] |
Tue, 15 October 2019 15:36  |
Eclipse User |
|
|
|
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
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  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.05257 seconds