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.  [ 5 posts ] 
Author Message
 Post subject: Select imbriqués avec Criteria
PostPosted: Fri Apr 13, 2007 2:36 pm 
Newbie

Joined: Fri Apr 13, 2007 2:17 pm
Posts: 8
Bonjour,

Je voudrais implémenter avec l'API Criteria une requete de select imbriqués portant sur plusieurs champs du type :
Code:
SELECT *
FROM X
WHERE ...
AND (champ1, champ2, champ3) IN (
    SELECT champ1, champ2, champ3
    FROM Y
    WHERE ...
    )


J'ai réussi à le faire quand le "in" ne porte que sur un seul champ :
Code:
SELECT *
FROM X
WHERE ...
AND champ1 IN (
    SELECT champ1
    FROM Y
    WHERE ...
    )


Criteria crit = getSession().createCriteria(X.class);

DetachedCriteria dcrit = DetachedCriteria.forClass(Y.class)
                        .setProjection( Projections.property("champ1") );

crit.add(Property.forName("champ1").in(dcrit));
...



Le problème est que je ne sais pas comment faire sur un triplet de champ ! Quelqu'un aurait-il une idée pour m'aider ?

Merci

_________________
Manu


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 15, 2007 3:21 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
De mémoire (je n'ai pas Hibernate ni mon envt eclipse sous la main) Projections.projectionList(...) ou quelque chose comme ça ?

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 16, 2007 4:09 am 
Newbie

Joined: Fri Apr 13, 2007 2:17 pm
Posts: 8
Oui pour le projectionList dans le DetachedCriteria je suis OK. Ma question protait surtout sur le Criteria. Qu'est-ce qu'on met dans le add ?
Code:
crit.add( ??? );


Merci

_________________
Manu


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 16, 2007 6:14 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
En SQL, ça correspondrait à quoi, ce que tu veux faire ?

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 16, 2007 6:17 am 
Newbie

Joined: Fri Apr 13, 2007 2:17 pm
Posts: 8
Quote:
SELECT *
FROM X
WHERE ...
AND (champ1, champ2, champ3) IN (
SELECT champ1, champ2, champ3
FROM Y
WHERE ...
)


ou par exemple cet exemple en HQL issu de la doc Hibernate :

Quote:
from Cat as cat
where ( cat.name, cat.color ) in (
select cat.name, cat.color from DomesticCat cat
)

_________________
Manu


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