Skip to content

Instantly share code, notes, and snippets.

@marti1125
Created February 25, 2014 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marti1125/9213979 to your computer and use it in GitHub Desktop.
Save marti1125/9213979 to your computer and use it in GitHub Desktop.
hibernate group
List<EventualidadDto> sumaTotalDeHoras = ((Session)JPA.em().getDelegate()).createCriteria(Eventualidad.class)
.setProjection( Projections.projectionList()
.add(Projections.sqlGroupProjection("sum({alias}.totalDeHoras) as sumaDeHoras", "{alias}.docente_codigo,{alias}.tipoEventualidad_id",
new String[]{"sumaDeHoras"}, new Type[] {DoubleType.INSTANCE}),"sumaDeHoras"))
.add( Restrictions.sqlRestriction(" ( {alias}.docente_codigo = ? ) ", new String[] {r.codigo}, new Type[] {StringType.INSTANCE}))
.add( Restrictions.sqlRestriction(" ( {alias}.tipoEventualidad_id = ? ) ", new Long[] {tipoEventualidad.id}, new Type[] {LongType.INSTANCE}))
.setResultTransformer(new AliasToBeanResultTransformer(EventualidadDto.class)).list();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment