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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:12:26+00:00 2026-05-27T04:12:26+00:00

im pretty sure this question anywhere already has been asked anywhere – didnt found

  • 0

im pretty sure this question anywhere already has been asked anywhere – didnt found the answer.

I got an simple Criteria like this:

s.createCriteria(Human.class).list()

gives me an resultlist of entityinstance of Human (gender and name).

Can i add an calculation like “salutation” to the resulting entityinstances only (without changing Human.java) and avoid the creation of an 2-dimensional array?

I know, this should be the job of such an Decorator-Class, is there any workaround? The enlarged entityinstance should extends the Human-class!

  • 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-27T04:12:27+00:00Added an answer on May 27, 2026 at 4:12 am

    No, it’s not completely possible. A Criteria query can only return entities, arrays of scalars, or value objects built from scalars (using a ResultTransformer).

    You could return a list of HumanWithSalutation objects, which would hold the same fields as a Human + an additional salutation one, but these would be value objects, and not persistent objects: any modification made to these objects would not be made persistent to the database as it would be with Human instances.

    To do that, create the class :

    public class HumanWithSalutation extends Human {
        private String salutation;
    
        // getter and setter
    }
    

    Assign it an AliasToBeanResultTransformer (which will populate all your HumanWithSalutation objects using setters), and make sure the criteria has a projection list returning all the fields of Human + the salutation (aliased to “salutation”):

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("id");
    projectionList.add(Projections.property("name");
    projectionList.add(Projections.property("gender");
    projectionList.add(Projections.alias(Projections.sqlProjection(...), "salutation"));
    criteria.setProjection(projectionList);
    

    If you don’t want the SQL projection, you could implement the transformation in Java in the getSalutation() method (and remove the setter).

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

Sidebar

Related Questions

i'm pretty sure that this question has allready been asked (but i didn't find
I'm pretty sure that this question already has been answered somewhere. It just seems
I am pretty much sure that this question have been asked and answered several
I'm pretty sure this is a simple question to answer and ive seen it
This may sound trivial, but I'm pretty sure this question hasn't been asked, or
Im pretty sure this has a simple solution. I am using jCarousellite, and i
I'm pretty sure I did this right, but my query has been running for
I've googled this question repeatedly, but have not found a great answer anywhere. I'm
I know this question has been asked alot of times, however most of them
I'm pretty sure this is a simple question in regards to formatting but here's

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.