-->
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: Criteria and Collections
PostPosted: Tue May 04, 2004 3:56 am 
Beginner
Beginner

Joined: Fri Oct 17, 2003 4:11 am
Posts: 40
Hallo!
I have a Parent class with some Children in a Set. I ask the user to give me some children's id and I use them to get the Parent that contains at least this children.
If the user give me only one child (with id=1 for example) it's simple:
Code:
Criteria criteria = session.createCriteria(Parent.class);
Criteria childrenCriteria = criteria.createCriteria("subChildren");
childrenCriteria.add( Expression.eq("id", new Integer(1)) );
List results = criteria.list();



If the user tell me "give me the Parent that have at least the children with id=1 and id=2" i tried with the conjunction of two Expression.eq but it doesn't work!! I get no result!
The whole code is:
Code:
Criteria criteria=session.createCriteria(HUtente.class);
HUtente hu=new HUtente();
hu.username="i%";
Example example=Example.create(hu);
example.ignoreCase();
example.enableLike();
example.excludeZeroes();
criteria.add(example);

Criteria childCriteria=criteria.createCriteria("gruppi");
childCriteria.add(Expression.conjunction().add(Expression.eq("id",new Long(1))).add(Expression.eq("id",new Long(2))));
List list=criteria.list();


There is a way to make this with Criteria (no Query)?
Please, help me! :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2004 4:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Try doing the child-criteria thing twice on the main criteria ...


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2004 7:41 am 
Beginner
Beginner

Joined: Fri Oct 17, 2003 4:11 am
Posts: 40
I trid with:
Code:
Criteria criteria=session.createCriteria(HUtente.class);
HUtente hu=new HUtente();
hu.username="i%";
Example example=Example.create(hu);
example.ignoreCase();
example.enableLike();
example.excludeZeroes();
criteria.add(example);

criteria.createCriteria("gruppi","x0").add(Expression.eq("id",new Long(1)));
criteria.createCriteria("gruppi""x1").add(Expression.eq("id",new Long(3)));

List list=criteria.list();


But i get: java.sql.SQLException: General error, message from server: "Unknown table 'x0' in where clause"

:( :( :(

The sql is:
Code:
select
this.id as id3_,
this.cognome as cognome3_,
this.descrizioneRuolo as descrizi3_3_,
this.grado as grado3_, this.nome as nome3_,
this.password as password3_,
this.username as username3_,
this.livelloPermessi as livelloP8_3_,
this.colonneAnagrafica as colonneA9_3_,
this.enteMilitare as enteMil10_3_,
hentemilit1_.id as id0_,
hentemilit1_.tipoEnte as tipoEnte0_,
hentemilit1_.nome as nome0_,
hentemilit1_.localita as localita0_,
hentemilit1_.email as email0_,
hentemilit1_.fax as fax0_,
hentemilit1_.indirizzo as indirizzo0_,
hentemilit1_.telefono as telefono0_,
hentemilit1_.firma as firma0_,
hentemilit1_.intestazione as intesta10_0_,
  hcomune2_.id as id1_,
  hcomune2_.nome as nome1_,
  hcomune2_.cap as cap1_,
  hcomune2_.nazione as nazione1_,
  hcomune2_.provincia as provincia1_,
  hcomune2_.regione as regione1_,
   x1.id as id2_,
   x1.nome as nome2_,
   x1.descrizione as descrizi3_2_,
   x1.permessiFormazione as permessi4_2_,
   x1.permessiCooperative as permessi5_2_,
   x1.permessiColloqui as permessi6_2_,
   x1.permessiCollocamento as permessi7_2_,
   x1.permessiBandi as permessi8_2_,
   x1.permessiAnagrafica as permessi9_2_,
   x1.permessiOfferte as permess10_2_,
   x1.permessiOrientamento as permess11_2_,
   x1.permessiSistema as permess12_2_,
   x1.permessiStati as permess13_2_,
   x1.tipologiaReportistica as tipolog14_2_
from ut_utente this
left outer join su_entemilitare hentemilit1_ on this.enteMilitare=hentemilit1_.id
left outer join su_comune hcomune2_ on hentemilit1_.localita=hcomune2_.id
inner join ut_utente_gruppo gruppi3_ on this.id=gruppi3_.idUtente
inner join ut_gruppo x1 on gruppi3_.idGruppo=x1.id where (1=1) and x0.id=? and x1.id=?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 05, 2004 11:59 am 
Beginner
Beginner

Joined: Mon Jul 05, 2004 9:29 am
Posts: 38
this problem seems to be recurrent... maybe a design flaw (?)

did someone find a solution that could have its place in the hibernate's best practices?


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.