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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:19:17+00:00 2026-05-26T14:19:17+00:00

I run a JPA 2.0 native query like this: Query query = em.createNativeQuery(SELECT NAME,

  • 0

I run a JPA 2.0 native query like this:

Query query = em.createNativeQuery("SELECT NAME, SURNAME, AGE FROM PERSON");
List list = query.getResultList();

now list has all the rows returned by the query. I can iterate over them, but every entry is an Object[] where:

  • at index 0 I find NAME
  • at index 1 I find SURNAME
  • at index 3 I find AGE

Did anyone find a way to do something like this:

Map<String, Object> row = list.get(index);
String name = row.get("NAME");
String surname = row.get("SURNAME");
Integer age = row.get("AGE");

I would need this since the native query that I execute is a dynamic one and I don’t know the order of the field in SELECT clause, so I don’t know id the query will look like:

SELECT SURNAME, NAME, AGE FROM PERSON

or

SELECT AGE, NAME, SURNAME FROM PERSON

or even

SELECT AGE, SURNAME, NAME FROM PERSON
  • 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-05-26T14:19:18+00:00Added an answer on May 26, 2026 at 2:19 pm

    Which JPA are you using – Hibernate, EclipseLink or something else?

    There is no standard way to do this in JPA but your specific implementation may allow it – for example, Eclipselink has a query result type hint.

    http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg03013.html

    Query query = entityManager.createNativeQuery(sql);
    query.setHint(QueryHints.RESULT_TYPE, ResultType.Map);
    

    For Hibernate, with javax.persistence.Query dbQuery:

    org.hibernate.Query hibernateQuery =((org.hibernate.jpa.HibernateQuery)dbQuery)
    .getHibernateQuery();
    hibernateQuery.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In hibernate I want to run this JPQL / HQL query: select new org.test.userDTO(
I'm trying to run a native query through JPA that uses a ':' character.
I run into similar codes like this all the time in aspx pages: <asp:CheckBox
I'm trying to evaluate the following JPQL query: select err from Error err where
I am trying to run this basic JPA/EJB code: public static void main(String[] args){
I'm trying to run the Tomcat with JBoss Embedded jpa booking example. I run
I'm trying to use JPA with GWT. My serviceImpl calls UserDAO.exists(user); When I run
We run full re-indexes every 7 days (i.e. creating the index from scratch) on
I am newbie with JPA. I'm trying to run some sample code using JPA
I run a query, where I count several sum s on the different fields

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.