I want to select all distinct records not a specific one and as entities.
I’m using Hibernate 5.6.15, JPA 2.2 and JDK 11 LTS
I tried it out though I know it’s a not proper query.
public List<Orders> custOrder() {
try ( Session session = HibernateUtil.getSessionFactory().openSession()) {
CriteriaBuilder cb = session.getCriteriaBuilder();
CriteriaQuery<Orders> cq = cb.createQuery(Orders.class);
Root<Orders> root = cq.from(Orders.class);
cq.select(root.get("transid")).distinct(true);
return session.createQuery(cq).getResultList();
}
}
So I want to select all distinct transid(s) but as entities not as String.
So how to do?
Kindly help.