Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.IllegalStateException: No explicit selection and an implicit one could not be determined

Tags:

jpa

Below is my jpa code.

    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery cq = cb.createQuery();
    Root e = cq.from(Student.class);
    cq.where(cb.greaterThan(e.get("id"), 3));
    Query query = entityManager.createQuery(cq);
    List<Student> students = query.getResultList();      

I want to get all the students whose id is greater than three. thanks.

like image 619
liam xu Avatar asked Sep 06 '25 04:09

liam xu


1 Answers

I guess you have to define the columns those will be selected from the table.

CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Student> cq = cb.createQuery(Student.class);
Root<Student> root = cq.from(Student.class);

cq.where(cb.greaterThan(e.get("id"), 3));
cq.select(root); // Which columns will be selected? Presuming all.

List<Student> studentList = entityManager.createQuery(cq).getResultList(); 
like image 181
hckey Avatar answered Sep 10 '25 16:09

hckey