Mapping JPA or Hibernate projection query to DTO (Data Transfer Object)

You have so many options for mapping your projection to a DTO result set: DTO projections using Tuple and JPQL List<Tuple> postDTOs = entityManager.createQuery(“”” select p.id as id, p.title as title from Post p where p.createdOn > :fromTimestamp “””, Tuple.class) .setParameter( “fromTimestamp”, Timestamp.from( LocalDateTime.of(2016, 1, 1, 0, 0, 0) .toInstant(ZoneOffset.UTC ))) .getResultList(); assertFalse(postDTOs.isEmpty()); Tuple postDTO … Read more