小编典典

给出java.lang.IllegalArgumentException的Hibernate查询:要遍历的节点不能为null

hibernate

这个简单的查询

session = com.jthink.songlayer.hibernate.HibernateUtil.getSession();
Query q = session.createQuery("recNo from SongChanges");

给这个堆栈跟踪

java.lang.IllegalArgumentException: node to traverse cannot be null!
    at org.hibernate.hql.internal.ast.util.NodeTraverser.traverseDepthFirst(NodeTraverser.java:63)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:272)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:180)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
    at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
    at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
    at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:119)
    at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:214)
    at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:192)
    at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1537)

如果我做

session = com.jthink.songlayer.hibernate.HibernateUtil.getSession();
Query q = session.createQuery("from SongChanges");

我没有收到错误,但我只需要recNo

有任何想法吗 ?


阅读 294

收藏
2020-06-20

共1个答案

小编典典

您忘记了选择:

Query q = session.createQuery("select sc.recNo from SongChanges sc");
2020-06-20