I have an object content that have a collection of roles.
I want to make a select, using criteria, of contents that have no roles.
Code:
Criteria createCriteria = session.createCriteria(Content.class);
createCriteria.add(Restrictions.isEmpty("allowedRoles"));
createCriteria.setFetchSize(200);
<class name="Content">
...
<set name="allowedRoles"
table="role_content" fetch="join">
<key>
<column name="content_id" not-null="true"/>
</key>
<many-to-many class="Role">
<column name="role_id" not-null="true" />
</many-to-many>
</set>
select * from (
select *
from content this_
inner join role_content allowedrol8_ on this_.id =allowedrol8_.role_content_id
inner join roletbl allowedrol3_ on allowedrol8_.role_id=allowedrol3_.id
where not exists (select 1 from role_content where this_.id=role_content_id)
) where rownum <= 200
hibernate generate me this query that is not correct because the result is always 0 because the join must be left outer join.
I try to set criteria.setFetchMode("allowedRoles", FetchMode.JOIN) but i have the same result.
I don't understand where is the problem. can someone help me?