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

  • Home
  • SEARCH
  • 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 7760705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:57:36+00:00 2026-06-01T13:57:36+00:00

Why I have to use Object[] to print the list if I select specific

  • 0

Why I have to use Object[] to print the list if I select specific columns:

Session session = DaoSF.getSessionFactory().openSession();
List<Object[]> list = new ArrayList<Object[]>(); /* Object[] */

Query criteria = session.createQuery(
  "select test.col1, test.col2, test.col3
  "from Test test " +
  "group by test.col1, test.col2, test.col3");

list = criteria.list();

for (Object[] item : list)
{
  System.out.println(item[1] + ", " + item[2] + ", " + item[3]); 
}

And why is it possible to iterate the same select (select * — not the specific columns) using original Test object?

List<Test> list = new ArrayList<Test>(); /* Test */
Query criteria = session.createQuery(
  "from Test test " +
  "group by test.col1, test.col2, test.col3");

list = criteria.list();

for (Test item : list)
{
  System.out.println(item.getCol1 + ", " + item.getCol2 + ", " + item.getCol3); 
}

Is it possible to “convert” Object[] to Test object?

  • 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-01T13:57:37+00:00Added an answer on June 1, 2026 at 1:57 pm

    Try this approach; first create a constructor in your Test class:

    public Test(Col1Type col1, Col2Type2 col2, Col3Type col3) {
      this.col1 = col1;
      this.col2 = col2;
      this.col3 = col3;
    }
    

    Now in the query, you can say:

    select new Test(t.col1, t.col2, t.col3) 
    from Test t
    

    This will give Hibernate a so-called row-mapper constructor out of which it can construct the objects of Test. Then you will have a List<Test> from query.list(). This approach has a catch that you should provide different constructors beside the default one for different possible queries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to use the XMLHttp object in classic ASP in order to send
I have a field that may be blank, so I need to use Object.try,
I have a singleton object that use another object (not singleton), to require some
Assuming I have to use C (no C++ or object oriented compilers) and I
I have to use scanf() for accepting name of user in NSString object. If
I have an link in HTML and I use Page Object pattern to write
Situation:- In my code I have to use the LWUIT Component object for the
I have a Javascript Map kit, and it use Image object to load images.
I have a object which contains unicode data and I want to use that
If I have a list of objects, I can use the __cmp__ method to

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.