hi,
in order to avoid hydrating full entities and fetch only the required field(s), is it actually possible with Blaze Persistence, without the entity views module (to keep it simple) ?
I have not found the DTOs in the Blaze-Persistence documentation, except for entity views module.
So we define a DTO and then simply use it. For example :
import java.time.LocalDateTime;
public record UserDTO(
String username,
String email,
LocalDateTime createdAt
) {}
and
EntityManager em = emHolder.getEntityManager();
CriteriaBuilderFactory cbf = CriteriaBuilderFactoryProducer.get(em);
List users = cbf.create(em, UserDTO.class)
.from(UserPO.class, āuā)
.selectNew(UserDTO.class,
āu.usernameā,
āu.emailā,
āu.createdAtā)
.where(āu.activeā).eqLiteral(true)
.orderByDesc(āu.createdAtā)
.getResultList();
Does it work ?
If not, how to do it and remain simple ? If it must be done with entity views module, what would be the approach, or please give a URL.
I emphasize that Blaze Persistence should be used for implementation, and not, for example, Hibernateās DTO projections (Hibernate is the JPA provider in the project).
The goal is to avoid hibernate entity hydration whenever possible, for performance purposes.
Thanks