This simple query
session = com.jthink.songlayer.hibernate.HibernateUtil.getSession();
Query q = session.createQuery("recNo from SongChanges");
giving this stacktrace
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)
if I do
session = com.jthink.songlayer.hibernate.HibernateUtil.getSession();
Query q = session.createQuery("from SongChanges");
I dont get the error, but I only need the recNo
Any ideas ?
You forgot the select:
Query q = session.createQuery("select sc.recNo from SongChanges sc");
This error also commonly happens when you use the method createQuery
to run a named query, instead of getNamedQuery
, for example:
session.createQuery("InvoiceItem.itemsFromInvoice")
when the correct approach would be
session.getNamedQuery("InvoiceItem.itemsFromInvoice")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With