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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:54:54+00:00 2026-05-14T03:54:54+00:00

I have a table with 11 columns, but I need to get only 2

  • 0

I have a table with 11 columns, but I need to get only 2 of them in my application, I’m using spring/hibernate/DAO combination. For now I have a domain class which includes all 11 fields, and mapping file which maps all 11 columns in table. How do I use get just 2 of them not all?

  • 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-14T03:54:54+00:00Added an answer on May 14, 2026 at 3:54 am

    Either:

    1. Use projections – Pro: nothing to add – Con: Not typesafe (the result is a List of rows where each row is anObject[]):

       select f.foo, f.bar from FatEntity f
      
    2. Use a constructor expression in the SELECT clause (the specified class is not required to be an entity or to be mapped to the database) – Pro: typesafe solution – Con: More classes, unless you reuse FatEntity as holder in which case many fields will be null:

       select new com.acme.FatEntityDetails(f.id, f.foo, f.bar) from FatEntity f
      

      Note that if an entity class name is specified in the SELECT NEW clause, the resulting entity instances are in the new state (no persistent identity).

    3. Use another entity mapped on the same table with only the required fields – Pro: It’s a real entity that you can modify and update – Con: More classes.

       from LightEntity
      

    The main differences between #2 and #3 are:

    • 2 doesn’t require the holder to be an entity at all.

    • the holder in #2 could be an entity mapped on another table.
    • if #2 returns entities, they are in a new state (this might be a problem, or not).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table where one column has duplicate records but other columns are
I have a table with columns ID, DateStamp and the ID need not be
I have a table that holds only two columns - a ListID and PersonID.
I have ten fields in my table in database..And two columns out of them
I have authlogic working fine but now have the need to let administrator users
I have a table with columns Index, Date where an Index may have multiple
I have a table with three columns: user varchar, status varchar , rep int
I have a table with four columns: PartNumber, ValvePartNumber, ActuatorPartNumber, Price I want to
I have a table with arbitrary columns and rows. This fact is irrelevant though
Let's say I have a table tbl with columns id and title . I

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.