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 8331113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:19:18+00:00 2026-06-09T02:19:18+00:00

In JPQL, I can retrieve entities by : query = entityManager.createQuery(select c from Category

  • 0

In JPQL, I can retrieve entities by :

query = entityManager.createQuery("select c from Category c");
List<Category> categories = query.getResultList();

But, if I wish to retrieve the id and name fields (only) of the Category entity, I need something like the ResultSet object, through which I can say : rs.getString("name") and rs.getString("id"). How to do this through JPQL, without retrieving the entire entity ?

Basically, for a how to retrieve information from a query like : select c.id,c.name from Category c ?

  • 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-09T02:19:19+00:00Added an answer on June 9, 2026 at 2:19 am

    In HQL you can use list() function to get a list of Object[] array that contains result rows:

    Query query = session.createQuery("select c.id,c.name from Category c");
    List<Object[]> rows = query.list();
    

    in returned array 1-st element will be id, second – name.

    for (Object[] row: rows) {
        System.out.println(" ------------------- ");
        System.out.println("id: " + row[0]);
        System.out.println("name: " + row[1]);
    }
    

    If you want to use hibernate’s Criteria API, you should use Projections.

    With JPA it will work the same way:

    List<Object[]> rows = entityManager.createQuery(queryString).getResultList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying the following JPQL and it fails misserably: Query query = em.createQuery(SELECT u
How can i write this sql in jpql syntax? SELECT SUM(t1.preise) FROM ( SELECT
JPQL queries can return custom result objects with the NEW operator: SELECT NEW myPackage.MyVO(e.fieldX,
I want to join two tables using JPQL : SELECT * FROM A LEFT
I'm having trouble figuring out how to represent the following JPQL query: SELECT count(e)
In hibernate I want to run this JPQL / HQL query: select new org.test.userDTO(
I want to make a JPQL query with a collection of non entities. This
I want to now if can JPQL retrieve the composed object. ObjectA has ObjectB
I can do this easily with JPQL that only returns data from one table.
Can you help me find the error in my JPQL query of the login

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.