-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate ignore fetch="join"
PostPosted: Tue Jan 12, 2010 10:19 am 
Newbie

Joined: Tue Jan 12, 2010 9:53 am
Posts: 1
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?


Top
 Profile  
 
 Post subject: Re: Hibernate ignore fetch="join"
PostPosted: Thu Jan 14, 2010 5:30 pm 
Newbie

Joined: Fri Jun 13, 2008 11:36 am
Posts: 13
try

<set name="allowedRoles"
table="role_content" fetch="join" lazy="false">

Explicitly setting lazy to false seems to have worked for me before. I'm not sure why fetch and lazy seem to be redundant parameters to me.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.