Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8375667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:14:06+00:00 2026-06-09T15:14:06+00:00

I have the following HQL in Hibernate using Spring MVC. List<Colour>list=session.createQuery(from Colour order by

  • 0

I have the following HQL in Hibernate using Spring MVC.

List<Colour>list=session.createQuery("from Colour order by colourId desc")
.setFirstResult((currentPage-1)*rowsPerPage)
.setMaxResults(rowsPerPage).list();

It works and returns a list of rows from the colour table (actually operates upon the Colour entity (POJO) that I can understand) in Oracle 10g.

What if I need to retrieve a list fields, I’m trying the following.

List<Colour>list=session.createQuery("colourId, colourName, colourHex from Colour order by colourId desc")
.setFirstResult((currentPage-1)*rowsPerPage)
.setMaxResults(rowsPerPage).list();

It ends with an excpetion

java.lang.IllegalArgumentException: node to traverse cannot be null!

In some articles, it was mentioned that the following version of HQL should (or may) work

List<Colour>list=session.createQuery("select colourId, colourName, colourHex from Colour order by colourId desc")
.setFirstResult((currentPage-1)*rowsPerPage)
.setMaxResults(rowsPerPage).list();

but unfortunately, it also didn’t work for me. Using the createSQLQuery() method to execute native SQL would work but I want to stick to the createQuery() method with HQL unless it’s absolutely necessary. How can I specify a list of fields in HQL?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:14:08+00:00Added an answer on June 9, 2026 at 3:14 pm

    I agree with yorkw’s comment. If you select properties in your query then you cannot ask for a List<Colour> object to be returned from a call to .list().

    Instead you should do this

        List<Object[]> rows = session.createQuery("select c.colourId, c.colourName, c.colourHex " +
            " from Colour c " + 
            " order by c.colourId desc").list();
    

    Then iterate over the list object and instantiate your objects. Or whatever you need to do.

        for ( Object[] row : rows ) {
            Long colourId = (Long)row[0];
            // ... etc
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following hibernate query - events = (List<Event>)session.createQuery( Event where eventName like
I need to replicate the following working HQL query using criteria API. session.CreateQuery( select
I have a following HQL query: SELECT s.id FROM stack s WHERE s.category is
I have the following code segment in which I'm getting error using (var session
I have the following setup. Spring 3.0.5 Hibernate 3.5.6 MySql 5.1 To save a
I have the following HQL query which works fine, however it returns a list
I have the following HQL( The Hibernate Query Language ) query (which is executed
Hello I have the following code to retrieve data from my db using nhibernate
I have a problem with the following HQL query: select sum(MYTABLE.COUNTER) from ( select
I have the following class structure FlowerDAO with the fields (mapped using Hibernate): id

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.