Folks!
Trying to limit amount of columns fetched from DB and found this: Hibernate Criteria Query to get specific columns
Criteria cr = session.createCriteria(User.class)
.setProjection(Projections.projectionList()
.add(Projections.property("id"), "id")
.add(Projections.property("Name"), "Name"))
.setResultTransformer(Transformers.aliasToBean(User.class));
List<User> list = cr.list();
This works awesome when you use Hibernate, but I am trying to do the same with JPA (JPA provider is Hibernate tho). Is it possible to do it with JPA? I mean limit columns with CriteriaBuilder and map to specific Object?
Also, I saw this: https://docs.jboss.org/hibernate/orm/5.0/userguide/html_single/chapters/query/criteria/Criteria.html
Hibernate offers an older, legacy org.hibernate.Criteria API which should be considered deprecated. No feature development will target those APIs. Eventually, Hibernate-specific criteria features will be ported as extensions to the JPA javax.persistence.criteria.CriteriaQuery. For details on the org.hibernate.Criteria API, see Legacy Hibernate Criteria Queries.
So seems like it is possible to do this via hibernate extensions for JPA?