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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:32:56+00:00 2026-05-23T17:32:56+00:00

In general, is it a better practice to write a new NamedQuery which selects

  • 0

In general, is it a better practice to write a new NamedQuery which selects a field,

@NamedQuery(name="getEntityField",
            query="select e.field from Entity e where <condition>")

or should one select e from Entity... and then build a new list?

List<Entity> entities = query.getResultList();
List<Object> fields = new ArrayList<Object>();
for (Entity e : entities) {
    fields.add( e.getField() );
}

If one of these patterns is better, why?

  • 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-23T17:32:56+00:00Added an answer on May 23, 2026 at 5:32 pm

    When you do it with a NamedQuery, the database only has to send a list with the content of that field back to the application, instead of complete entities (all the columns of a table).

    On the other hand, if the entities are already in the cache of your ORM framework, then to get the entities it doesn’t even have to go to the database at all.

    It might also be that your ORM framework is smart enough to understand the query, so that it can do the query from its cache instead of going to the database.

    What works best depends on the situation of your application and the ORM framework that you are using. Try out both methods, let your ORM framework log what it does, and look through the log to see what it does and determine which is better for your particular application.

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

Sidebar

Related Questions

I'm developing a store which gets its product info from lots of xml feed,
Is there a better to handle running multiple regular expressions in PHP (or in
I want to ask a general question about the proper way to handle a
I'm slowly making my way through the rails source, to get a better grip
I'm not posting any code here, because the question is more general. So I
I recently ran into major problems inserting records into a SQL Server backend from
My buddy says that he tries to program with as little if/else statements as
I need to do require_once for my wp plugin development. It seems to me
The site I am building includes a homepage composed of panels of summarised tabular
Defined this way, we can do neither ++x++ nor ++x-- . But on the

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.