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

Which is better in general in terms of the ordering? Do you put the
In general, which performs better? How are they like when processing vector graphics?
I just wanted to get the general consensus on which is a better mode
Give me some of your thoughts on which is a better coding practice/makes more
I'm trying to get a better understanding of general practice... specifically deriving this() in
In general, is it better to have a web application make lots of calls
General javascript question here, which would also be good to know how(if possible) to
just looking for some general direction/best practice about when to use a lookup value
I am quite new to unit testing and testing in general. I am developing
Just a general question about what the best practice is: public void Foo() {

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.