Reputation: 139
I have a structure like this:
I'd like to make a query, that retrieves A objects, that contain B objects without the C objects within them. Is that possible? The other way around will work for me too (if B-C relation is mapped lazy and the query retrieves A, containing B and C).
Thanks!
Upvotes: 8
Views: 14414
Reputation: 691735
No, it's not possible. Since you marked the association itself as eagerly-loaded, Hibernate will always load this association eagerly.
If you mark the association as lazy (the default for toMany associations), then you have th option of eagerly fetching them in a query, using a join fetch
:
select a from A a left join fetch a.bs b left join fetch b.cs
Note that this will not work if both of the collections are bags (i.e. Lists without index column).
Upvotes: 9