我在使用Spring MVC的Hibernate中擁有以下HQL。在HQL中指定字段列表似乎不起作用
List<Colour>list=session.createQuery("from Colour order by colourId desc")
.setFirstResult((currentPage-1)*rowsPerPage)
.setMaxResults(rowsPerPage).list();
它的工作原理,並返回從顏色表中的行Oracle 10g中的列表(實際上在顏色實體(POJO),我能理解工作)。
如果我需要檢索列表字段,我在嘗試以下操作。
List<Colour>list=session.createQuery("colourId, colourName, colourHex from Colour order by colourId desc")
.setFirstResult((currentPage-1)*rowsPerPage)
.setMaxResults(rowsPerPage).list();
它有錯誤時拋出
java.lang.IllegalArgumentException: node to traverse cannot be null!
在一些文章,提到結束該HQL以下版本應該(或可以)工作
List<Colour>list=session.createQuery("select colourId, colourName, colourHex from Colour order by colourId desc")
.setFirstResult((currentPage-1)*rowsPerPage)
.setMaxResults(rowsPerPage).list();
但不幸的是,它也沒有爲我工作。使用createSQLQuery()
方法來執行本機SQL可行,但我想堅持使用HQL的createQuery()
方法,除非絕對必要。我如何在HQL中指定一個字段列表?
嘗試'列表