Saturday, August 21, 2021

Interface-based Projections of the Result of JPA Queries

 public interface ICommentCount {

    Integer getYearComment();

    Long getTotalComment();

}


@Query("SELECT c.year AS yearComment, COUNT(c.year) AS totalComment "

  + "FROM Comment AS c GROUP BY c.year ORDER BY c.year DESC")

List<ICommentCount> countTotalCommentsByYearInterface();


more example

@Query(value = "SELECT user.firstname AS firstname, user.lastname AS lastname FROM SD_User user WHERE id = ?1", nativeQuery = true)

NameOnly findByNativeQuery(Integer id);

No comments:

Post a Comment