-->
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.  [ 4 posts ] 
Author Message
 Post subject: Joins using Criteria
PostPosted: Thu Jan 11, 2007 5:17 am 
Newbie

Joined: Thu Jan 11, 2007 4:51 am
Posts: 1
Hi,

Would like to check if it is possible to add multiple join conditions using criteria

E.g. adding a criteria : criteria.createCriteria("chlid") generates
Code:
left outer join
        childTable_
        on this_.ID=childTable.Parent_ID


I.e. i need to get the following join condition in SQL

Code:
left outer join
        childTable_
        on this_.ID=childTable.Parent_ID and childTable.is_active='Y'


How should it be done? is it possible with criteria at all?

thanks for the help in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 23, 2007 8:54 am 
Newbie

Joined: Tue Jan 23, 2007 8:43 am
Posts: 1
Location: Belgium
Did you find already a solution for your problem?

I'm trying to do the same, but didn't have success with the Criteria API. Maybe I should try with HQL?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 21, 2007 1:30 pm 
Newbie

Joined: Fri Dec 21, 2007 1:27 pm
Posts: 1
Any news regarding how to solve this not using HQL ?


Top
 Profile  
 
 Post subject: multiple joins
PostPosted: Thu Dec 27, 2007 2:08 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
    assuming they are already properly joined by ID on your mapping file
    assuming you have a getChildren property on your main bean


Code:
Criteria crit=session.createCriteria(ParentTableBean.class);
Criteria childCrit=crit.createCriteria("children");
childCrit.add(Restrictions.eq("active", "Y"));

List result=childCrit.list();


notice that you ask for the list on the child criteria, not the main one.

notice that "active='Y' is not part of the join condition, but part of the "WHERE clause"

Gonzalo Díaz


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.