This simple query
session = com.jthink.songlayer.hibernate.HibernateUtil.getSession();
Query q = session.createQuery(\"recNo from SongChanges\");
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")
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.