gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 01:33:29 25 4
gpt4 key购买 nike

下面是我的 jpa 代码。

    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();

我想得到所有id大于3的学生。
谢谢。

最佳答案

我想您必须定义将从表中选择的列。

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();

关于jpa - java.lang.IllegalStateException : No explicit selection and an implicit one could not be determined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50231748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com