-->
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.  [ 3 posts ] 
Author Message
 Post subject: Criteria Help
PostPosted: Fri Jul 10, 2009 5:37 am 
Newbie

Joined: Wed Jun 03, 2009 10:05 am
Posts: 9
Hi!
I want to do a query with Criteria.

I've this relations:

Usuario 1 ------- * Firma
Firma * ------- 1 Circuito

And these classes:

class Usuario:
private Integer idUsuario;
private Set<Firma> firmas = new HashSet<Firma>(0);

class Firma
private Integer idFirma;
private Usuario usuario;
private Circuito circuito;

Circuito
private Integer idCircuito;
private Set<Firma> firmas = new HashSet<Firma>(0);

I want obtain for a Circuit, all Usuarios that don't have Firma.

Thank you!!


Top
 Profile  
 
 Post subject: Re: Criteria Help
PostPosted: Fri Jul 10, 2009 10:51 am 
Newbie

Joined: Wed Jun 03, 2009 10:05 am
Posts: 9
The query that I need is this:

select Usuario
from Usuarios u
where Usuario not in
(select Usuario from
Firmas f,
Circuito c
where c.idCircuito = f.idCircuito and
c.idCircuito = ?);


Top
 Profile  
 
 Post subject: Re: Criteria Help
PostPosted: Mon Jul 13, 2009 3:43 am 
Newbie

Joined: Wed Jun 03, 2009 10:05 am
Posts: 9
I got it with two queries:
Can someone simplify this?


List<Usuario> idUsuarios = getSession()
.createCriteria(Usuario.class)
.setProjection(Projections.property("idUsuario"))
.createCriteria("firmas")
.createCriteria("circuito")
.add(Expression.eq("idCircuito", circuito.getIdCircuito()))
.list();

List<Usuario> results = getSession()
.createCriteria(Usuario.class)
.add(Expression.not(Expression.in("idUsuario", idUsuarios)))
.list();


Thanks!


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