0

I'm using jpa criteria for my select clause. I'm not able to get the result set. Here is my code

CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
Root<PKEntity> root = cq.from(PKEntity.class);
List<Object[]> resultlist = em.createQuery(cq).getResultList();

It throws the following error

No terms is selected for criteria query. Use CriteriaQuery.select or multiselect.

What I'm doing wrong here? I'm using my mobile to post.. so I'm sorry I could nt post the whole stacktrace

Syed
  • 2,471
  • 10
  • 49
  • 89

3 Answers3

0

Your cq.select function is missing. Add

cq.select(what do you want);

after then

Root<PKEntity> root = cq.from(PKEntity.class);
Utku Soytaş
  • 1,475
  • 2
  • 19
  • 30
0

try adding Restriction in your criteria. Restriction is basically similar to a "Where" clause.

Nabarun Dey
  • 104
  • 9
0
public List<Object[]> loadAllObj() {
    CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
    CriteriaQuery<Object[]> query = criteriaBuilder .createQuery(Object[].class);
    Root<PKEntity> variableRoot = query.from(PKEntity.class);
    query.select(variableRoot);
    return em.createQuery(query).getResultList();
} 
Khalil M
  • 1,788
  • 2
  • 22
  • 36