-->
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.  [ 6 posts ] 
Author Message
 Post subject: Query to Criteria
PostPosted: Wed Jun 03, 2009 10:22 am 
Newbie

Joined: Wed Jun 03, 2009 10:05 am
Posts: 9
Hi!

I need your help!
I have this query and I need to do with Criteria:

select ifnull(count(i.id),0) as num_incidencias, ti.id, ti.descripcion
from tipos_incidencia ti left join incidencias i on i.id_tipo_incidencia = ti.id
group by ti.descripcion
order by num_incidencias desc

I need to get all objects TipoIncidencia sorted by number of occurrences in Incidencias.

Thanks a lot!!


Top
 Profile  
 
 Post subject: Re: Query to Criteria
PostPosted: Wed Jun 03, 2009 11:00 am 
Newbie

Joined: Wed Jun 03, 2009 10:14 am
Posts: 5
Try this...

Code:
Criteria.createCriteria(Incidencia.class);
Criteria.createCriteria("tipoIncidencia","ti");
criteria.setProjection(Projections.projectionList().add(
   Projections.count("ti.cdTipoIncidencia"), "ocurrurences").add(
      Projections.groupProperty("ti.cdTipoIncidencia")));
criteriaAtendimento.addOrder(Order.asc("ti.cdTipoIncidencia"));


Im waiting feedback.


Top
 Profile  
 
 Post subject: Re: Query to Criteria
PostPosted: Thu Jun 04, 2009 11:50 am 
Newbie

Joined: Wed Jun 03, 2009 10:05 am
Posts: 9
Ok, thanks but it didn't work.

I try to explain better.

I' ve two classes with a bidirectional relation:

TipoIncidencia:
private Long id;
private String descripcion;
private Set<Incidencia> incidencias;

Incidencia:
private Long id;
private String codigo;
private TipoIncidencia tipo;

I need return all Objects TipoIncidencia sorted by ocurrences of this object in Incidencia's.

Example:

Incidencia A: --> TipoIncidencia1
Incidencia B: --> TipoIncidencia2
Incidencia C: --> TipoIncidencia2
Incidencia D: --> TipoIncidencia2
Incidencia E: --> TipoIncidencia3
Incidencia F: --> TipoIncidencia3

The result will be: return List {TipoIncidencia2, TipoIncidencia3, TipoIncidencia1}

Thanks again!


Top
 Profile  
 
 Post subject: Re: Query to Criteria
PostPosted: Tue Jun 09, 2009 2:46 am 
Newbie

Joined: Wed Jun 03, 2009 10:05 am
Posts: 9
Someone can help me please?
Thanks!


Top
 Profile  
 
 Post subject: Re: Query to Criteria
PostPosted: Tue Jun 23, 2009 3:07 am 
Newbie

Joined: Wed Jun 03, 2009 10:05 am
Posts: 9
...please!


Top
 Profile  
 
 Post subject: Re: Query to Criteria
PostPosted: Tue Jun 23, 2009 3:36 am 
Newbie

Joined: Tue Jun 23, 2009 3:31 am
Posts: 10
Could u explain the problem in more detail?
Could u show the table structure along with data?
What is the expected output?


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