-->
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.  [ 1 post ] 
Author Message
 Post subject: Change order outer joins are executed within criteria
PostPosted: Thu Jul 01, 2010 4:08 am 
Newbie

Joined: Thu Jul 01, 2010 3:51 am
Posts: 3
Hi all,

Does anyone knows how to change the order a Criteria generates its JOINs? Let me use an example.

I have this criteria (with DetachedCriteria modified by me to accept the withClause in the join):

Code:
DetachedCriteria criteria = DetachedCriteria.forClass(Customer.class);
criteria.createCriteria("pc.protocol", "pcp");
criteria.createCriteria("protocolCustomer", "pc");
criteria.createCriteria("group", "gr");
criteria.createCriteria("gr.protocolGroupSet", "pgs", Criteria.INNER_JOIN, Restrictions.eqProperty("protocolGroupPK.protocolId", "pcp.protocolId"));


This criteria generates this SQL code:

Code:
select
        *
    from
        CUSTOMERS this_
    inner join
        COMPANY_GROUPS gr3_
            on this_.GROUP_ID=gr3_.GROUP_ID
    inner join
        PROTOCOL_GROUP pgs4_
            on gr3_.GROUP_ID=pgs4_.GROUP_ID
            and (
                pgs4_.PROTOCOL_ID=pcp1_.PROTOCOL_ID
            )
    inner join
        PROTOCOL_CUSTOMER pc2_
            on this_.CUSTOMER_ID=pc2_.CUSTOMER_ID
    inner join
        PROTOCOL pcp1_
            on pc2_.PROTOCOL_ID=pcp1_.PROTOCOL_ID


and this throws a SQL Error because this line: pgs4_.PROTOCOL_ID=pcp1_.PROTOCOL_ID. This is completely normal because at the moment this query is trying to be executed, pcp1_ alias has not yet been defined. This would be resolved if I can change the inner join with PROTOCOL_GROUP to the last position, after the inner join with PROTOCOL.

Can i modify the order in which the JOINs are executed within a Criteria?

Thank you.


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

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.