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

The Archive Base Latest Questions

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

My data access classes often have a method called loadDataToEntity or something similar. This

  • 0

My data access classes often have a method called loadDataToEntity or something similar. This method takes a resultset for instance and populates an entity class which is passed on to be used by the client.

This is nice because all methods which use a stored procedure to retrieve data can just pass the resultset to the loadDataToEntity method and get back an entity.

So it’s a good way to reduce code but I often hear that you should retrieve as few columns as possible. To use my general method all stored procedures needs to fetch all columns needed for loadDataToEntity(). Also, when a column is added to the table and is retrieved by a stored procedure all other stored procedures needs to be altered and also retrieve that column.

I’m wondering if there’s a better way to both achieve a general method and also retrieve different number of columns sometimes depending on the stored procedure?

 
public Entity getById(int id)  
{    
    ResultSet rs;
    //call stored procedure A and stuff  
    return loadDataToEntity(rs);  
}  
public Entity getByName(String name)
{
    ResultSet rs;
    //call stored procedure B and stuff
    return loadDataToEntity(rs);
}
public Entity loadDataToEntity(ResultSet rs)
{
    // fill and return entity here
}
 
  • 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-17T22:23:32+00:00Added an answer on May 17, 2026 at 10:23 pm

    It really depends on how you’ve organised the different categories of entity within your database and how you’re retrieving them. For example, if you have one large denormalised table that can contain many entity types with each type requiring a different combination of columns being populated then you will have to retrieve all columns if you wish to retrieve all entity types in a single query.

    Conversely if you’ve organised your database schema in a normalised form you might well have a parent entity table (which might simply contain entity ID) and multiple sub-tables, one per entity type. In this case you could run multiple bespoke queries to retrieve the various entity types; e.g.

    select E.EntityId, S.EntityName, S.EntityAge
    from Entity E
    inner join SubEntity S on E.EntityId = S.EntityId
    

    or

    select E.EntityId, A.EntityAddress, A.EntityGender
    from Entity E
    inner join AnotherSubEntity A on E.EntityId = S.EntityId
    

    The trade-off with this second approach is the need to run multiple queries, which could in fact be slower. However, I’ve resolved this in my application by running the queries in parallel and multiplexing the results together within the application.

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

Sidebar

Related Questions

No related questions found

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.