Skip to content

Instantly share code, notes, and snippets.

@KeyCuevasMelgarejo
Last active November 29, 2020 04:34
Show Gist options
  • Save KeyCuevasMelgarejo/9c0bf9e5f939358991f369435064ca3d to your computer and use it in GitHub Desktop.
Save KeyCuevasMelgarejo/9c0bf9e5f939358991f369435064ca3d to your computer and use it in GitHub Desktop.
Spring | Repository | JPA@query

Repository JPA @query | Ejemplo

	@Query(value = "SELECT Max(id_horario) FROM Horario")
	Integer findByHorario_IdHorario();
	
	@Query(value = "SELECT h FROM Horario h where h.estado_registro='PENDIENTE'")
	List<Horario> findByEstado();
	
	@Query(value = "SELECT h FROM Horario h where h.estado_registro='COMPLETADO'")
	List<Horario> findByEstadoCompletado();
	
	@Query("SELECT h.curso.nombre_curso, count(h.curso.nombre_curso) as ranking FROM Horario h GROUP BY h.curso.nombre_curso order by ranking DESC")
	List<Object[]> findByCursoMasSolicitado();
	
	@Query("SELECT h.alumno.nombres, count(h.alumno.nombres) as ranking FROM Horario h GROUP BY h.alumno.nombres order by ranking DESC")
	List<Object[]> findByAlumnoQueGeneraMasSolicitudes();
@KeyCuevasMelgarejo
Copy link
Author

KeyCuevasMelgarejo commented Nov 29, 2020

Claro.
Igual chequea la documentación oficial, hay cosas interesantes, incluso es posible que no necesites utilizar @query y solo utilizar las funciones que el mismo JPA prepara a través de tus entities creadas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment