Hibernate query giving java.lang.IllegalArgumentException: node to traverse cannot be null

前端 未结 3 1013
刺人心
刺人心 2021-01-03 01:14

This simple query

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


        
相关标签:
3条回答
  • 2021-01-03 01:36

    You forgot the select:

    Query q = session.createQuery("select sc.recNo from SongChanges sc");
    
    0 讨论(0)
  • 2021-01-03 01:43

    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")
    
    0 讨论(0)
  • 2021-01-03 01:46

    The SELECT clause provides more control over the result set than the from clause. If you want to obtain few properties of objects instead of the complete object, use the SELECT clause. Following is the simple syntax of using SELECT clause to get just name field of the Employee object:

    String hql = "SELECT E.name FROM Employee E";
    Query query = session.createQuery(hql);
    List results = query.list();
    

    If you want whole object that time "select * from" is not needed.

    0 讨论(0)
提交回复
热议问题