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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:22:34+00:00 2026-05-26T11:22:34+00:00

In my current project I need to perform a few native queries which pick

  • 0

In my current project I need to perform a few native queries which pick some fields from tables joined in the query e.g.:

SELECT t1.col1, t2.col5
FROM t1
JOIN t2 ON t2.id = t1.t2_id

I tried to store them in a class like

class Result {
  String t1_col1;
  String t2_col5;
}

using

Query q = entityManager.createNativeQuery( "THE SQL SELECT" , Result.class );

JPA now complains (“uknown entity: result”) that the class ‘result’ isn’t an entity which is probably required to map the columns into the object.
I also tried to repeat the @Column declarations in the result class.

My question is how can I declare this without having to create the entites represented as tables in my DB?

  • 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-26T11:22:34+00:00Added an answer on May 26, 2026 at 11:22 am

    If you’re using JPA/Hibernate to perform SQL queries, then you’re using the wrong tool. Hibernate is an ORM, and you’re supposed to map tables to entities. That’s the whole point of JPA. I you just want to perform SQL queries, use JDBC (and Spring’s JdbcTemplate for example)

    Once table1 and table2 are mapped to entities (let’s call these entities T1 and T2), you won’t need these SQL queries anymore, because JPQL is able to select only some fields of the entities. Your query could the look like this (depending on the association between t1 and t2):

    select t1.col1, t2.col5 from T1 t1 join t1.t2 t2
    

    And you would just have to iterate over the result (a list of Object[]) to build your results (which is a DTO and not a mapped entity) :

    List<Object[]> rows = (List<Object[]>) query.list();
    List<Result> listOfResults = new ArrayList<Result>(rows.size);
    for (Object[] row : rows) {
        listOfResults.add(new Result((String) row[0], (String) row[1]));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On my current project we generate JAXB beans from an XSD file. We need
In the current project I need to communicate with third-party web services from .NET.
In my current project, i need to call a Unix shell script from the
For my current project in c# I need to transfer data from a SQL-Database
In my current project, I need to add information from an xml file to
In my current project, I have quite a few objects I need to persist
In my current iPhone project I need to decrypt zip files which have been
In a current project I need to support finding a User by login credentials
In a current project i need to display PDFs in a webpage. Right now
Successfully used jquery-infinite-carousel in the past but for my current project I need it

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.