-->
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.  [ 7 posts ] 
Author Message
 Post subject: Criteria and many to many query + like or in clause
PostPosted: Wed Sep 17, 2008 3:09 pm 
Beginner
Beginner

Joined: Tue Jun 06, 2006 3:37 am
Posts: 29
Hi,

I've a problem while I'm trying to execute a query I need to do the following sql query within the use of criteria or hql

Code:
select affaire.nom, affaire.id ... from affaire, requerant, affaire_requerant where affaire_requerant.ref_affaire = affaire.id_affaire and affaire_requerant.ref_requerant = requerant.id_requerant and requerant.nom like '%Jaq%?



in my Affaire entity I've a set of Requerant declared

I first load all the requerant that meets the like clause and then try to use a

Code:
criteria.createCriteria(Affaire.class)
Criteria testMany = criteria.createCriteria("requerants");
testMany.add(Restrictions.in("id", getRequerantsArray());
criteria.list()


where getRequerantsArray return an array of id of the eligible requerant

any idea ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 17, 2008 6:44 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Code:
Criteria critAff==session.createCriteria(Affaire.class);
Criteria critReq=critAff.createCriteria("requerants");
critReq.add(Restrictions.like("nom", "%Jaq%");
critReq.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
return critReq.list();

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 17, 2008 8:35 pm 
Beginner
Beginner

Joined: Tue Jun 06, 2006 3:37 am
Posts: 29
The problem with this solution is I have to do it with

affaire.requerants.nom
affaire.requerants.prenom
affaire.requerants.dateNaissance

andd all the fields of other relations

this is definitly not possible to subquery temporary subset of already retrieved elements list ? by using subquery or detached criteria ?

the getRequerantsArray() already filter all data related to a specifc relation


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 17, 2008 10:03 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Je ne comprends pas quel est le problème.
Donne-moi quelques details de plus, s.t.p.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 1:13 am 
Beginner
Beginner

Joined: Tue Jun 06, 2006 3:37 am
Posts: 29
Criteria critReq=critAff.createCriteria("requerants");
critReq.add(Restrictions.like("nom", "%Jaq%");

mean affaire.requerans.requerant.nom ? ???


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 1:21 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
oui

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 2:03 am 
Beginner
Beginner

Joined: Tue Jun 06, 2006 3:37 am
Posts: 29
parfait merci beacoup :)


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