Ok, I have an entity class with a List member that maps through Hibernate to a large list of objects. I do not need to fetch the entire list at query time, I only need the total size of objects that this applies to.
- List also uses the @Where annotation to only select a
subset of the elements. - List is marked as
@LazyCollection(LazyCollectionOption.EXTRA) due to its very large size - Mapping is done through the use of a link table
- List has the following sort of mapping:

The @JoinTable of the List uses a join on table 2 and an inverse join on table 3. I am not entirely sure what the SQL generated is because I am not too fluent in SQL.
Anyways, the @Where clause will have some restrictions on it, such as ‘STATUS = ACTIVE’ and possibly some other stuff such as ‘LETTER = ‘A’. Like the example shows, if I do a call like this:
List items = Lists.getItems(); items.size(); // This results in 1 with the restrictions with the @Where clause
The above populates the items with the correct items from Table 3 with the restrictions of the @Where clause.
The first thing I tried without fetching the entire list was this:
int listSize = Lists.getItems().size(); // This results in 3, the @Where clause is not applied
I researched it, and found this issue with Hibernate that I do not believe has been fixed: Hibernate Jira
So, my question is what is the best way to do this? I am not very proficient in SQL or HQL, yet. I am not too familiar with joins and other database terminology, so if any support could be given that would be great.
Thanks!
I ended up doing the following query and setting the parameter: